每次从背景和按钮打开我的应用程序时,如何使用此功能?
Swift 3
tableView.reloadData()
非常感谢你!
答案 0 :(得分: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()
}