swift程序进入后台

前端之家收集整理的这篇文章主要介绍了swift程序进入后台前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
class ViewController: UIViewController {
    
    @IBOutlet weak var message: UILabel!
    @IBOutlet weak var myNotification: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        NSNotificationCenter.defaultCenter().addObserver(self,selector: #selector(ViewController.updateInterface(_:)),name: UIApplicationWillEnterForegroundNotification,object: nil)
    }
    
    func updateInterface (notification: NSNotification){
        myNotification.text = "Back to background with notification"
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
}
按下home键之后,myNotification的text永久的改为 "Back to background with notification"

猜你在找的Swift相关文章