ios - 带有单例字符串的 UILabel.text 为 nil - 警告 : Attempt to present ** whose view is not in the window hierarchy

标签 ios swift2 singleton uilabel

我有一个虚拟问题...

在我的一个 ViewController 中,我设置了一个 UILabel 文本,其中包含一个来自单例的 String var:

var nom: String!
var prenom: String!

override func viewDidLoad() {
.....
self.nom = User.sharedInstance.nom
self.prenom = User.sharedInstance.prenom
....
print("User: \(self.nom) - \(self.prenom)")
self.labelWelcome.text = ("Bienvenue \(self.prenom) \(self.nom)")

打印显示正确的用户值,但我的 View 显示 Bienvenue nil nil....

有什么想法吗?

最佳答案

试试这个:

if let nom1 = self.nom {
    print("User: \(nom1)")
}

关于ios - 带有单例字符串的 UILabel.text 为 nil - 警告 : Attempt to present ** whose view is not in the window hierarchy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38260796/

相关文章:

swift2 - AVAssetWriter输入: how to get the right aspect ratio of the images within the movie?

ios - 在 swift 2.0 中构建自定义相机应用程序时出错

ios - 从 'AUAudioUnitBus?' 转换为无关类型 'UICollectionViewLayoutAttribute' 总是失败 - swift 2 iOS 9

c++ - 使用 libcurl 的线程安全代理

java - 观察者主题单例模式?

ios - Apple 的反向地理编码国家列表

ios - 重命名 IPA 应用名称

c++ - C++中的单例模式

iphone - 类型名称未知Iphone错误

ios - 使用 swift 3 中的计时器自动更改 UIPageViewController 中的页面?