2016-12-16 60 views

回答

4

趕上前臺通知:

class ViewController: UIViewController { 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     NSNotificationCenter.defaultCenter().addObserver(self, selector: "willEnterForeground:", name: UIApplicationWillEnterForegroundNotification, object: nil) 
    } 

    func willEnterForeground(notification: NSNotification!) { 
     // do whatever you want when the app is brought back to the foreground 
     self.tableView.reloadData() 
    } 

    deinit { 
     // make sure to remove the observer when this view controller is dismissed/deallocated 

     NSNotificationCenter.defaultCenter().removeObserver(self, name: nil, object: nil) 
    } 
} 

刷新您的實現代碼如下:

override func viewDidLoad() { 
    super.viewDidLoad() 

    self.tableview.reloadData() 
} 
+0

感謝您的回答,它是快速3代碼? – dmarinkin

+0

你可以測試。也許它是兼容:)(swift 2.2) –

+0

謝謝,它的工作原理! – dmarinkin

相關問題