我试图在应用程序进入前台时更改标签上的文本,但我总是得到 p>
fatal error :在展开可选值时意外发现 nil
ViewController.swift
@IBOutlet var textLabel: UILabel!
func showLabel() {
textLabel.text = "Welcome back"
}
和
AppDelegate.swift
func applicationWillEnterForeground(application: UIApplication) {
ViewController().showLabel()
}
知道如何解决吗?
最佳答案
谢谢解答!我用
管理它NSNotificationCenter.defaultCenter().addObserver(self, selector: "showLabel", name: UIApplicationDidBecomeActiveNotification, object: nil)
在viewDidLoad中
然后在 AppDelegate 中
func showLabel() {}
基于: Nil when unwrapping an Optional Value in didBecomeActive()
关于ios - applicationWillEnterForeground 为 textLabel 找到 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28032505/