Search code examples
iosswiftnsnotificationcenterviewdidloadviewdidappear

How to detect the closing of the NofiticationCenter in Swift / Xcode?


I have a UITableView and I want to to reload, when the NotificationCenter has been dismissed over the running app.

override func viewDidLoad() {
    super.viewDidLoad()
    self.tableView.reloadData()

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

}

func dismissedNC() {

    println("NC has been dismissed") // doesn't get printed
    self.tableView.reloadData()
}

Any ideas why it doesn't work?


Solution

  • While the notification center was present, the app was never in the background, so it does not come to the foreground when the notification center is dismissed - and so there is no UIApplicationWillEnterForegroundNotification. The app is activated, not foregrounded. Watch for UIApplicationDidBecomeActiveNotification instead.