gpt4 book ai didi

swift - 刷新 applicationWillEnterForeground 上的 UILabel

转载 作者:搜寻专家 更新时间:2023-11-01 07:01:50 24 4
gpt4 key购买 nike

我试图在应用程序从后台状态返回时刷新标签,但是我找不到引用该标签的方法。

但是,如果我在应用程序委托(delegate)的 applicationWillEnterForeground 下添加 label.text = titles[emotionOfTheDay],它会正确地告诉我它不知道我在说什么标签,因为标签在我的 ViewController 中。有没有一种方法可以从不同的文件中引用这个标签,或者我是不是用错了方法?

谢谢。

最佳答案

你需要实现

override func viewDidLoad() {
NotificationCenter.default.addObserver(self, selector: #selector(willEnterForeground), name: UIApplication.willEnterForegroundNotification, object: nil)

}

deinit {
NotificationCenter.default.removeObserver(self, name: UIApplication.willEnterForegroundNotification, object: nil)
}

@objc fileprivate func willEnterForeground() {
// refresh the label here
}

关于swift - 刷新 applicationWillEnterForeground 上的 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50788998/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com