代码之家  ›  专栏  ›  技术社区  ›  CristianMoisei

刷新应用程序上的uiLabel将进入前台

  •  1
  • CristianMoisei  · 技术社区  · 6 年前

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

    但是,如果我在applicationwillenterforeground下添加label.text=titles[emotionofday]到应用程序的委托中,它会正确地告诉我它不知道我在说什么标签,因为标签在我的viewcontroller中。有没有办法从另一个文件引用这个标签,或者我这样做是不对的?

    谢谢。

    1 回复  |  直到 6 年前
        1
  •  2
  •   Shehata Gamal    6 年前

    你需要实施

    override func viewDidLoad() {
        NotificationCenter.default.addObserver(self, selector: #selector(willEnterForeground), name: .UIApplicationWillEnterForeground, object: nil)
    
    }
    
    deinit { 
        NotificationCenter.default.removeObserver(self, name: .UIApplicationWillEnterForeground, object: nil)
    }
    
    @objc fileprivate func willEnterForeground() {
        // refresh the label here 
    }