我想在Swift 2.0中使用NSNotificationCenter .They do not call来调用一个方法。我是Swift的新人。请帮帮忙。任何帮助都会得到重视。
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let landingView = NewsViewController(nibName : "NewsViewController", bundle: nil)
NSNotificationCenter.defaultCenter().postNotificationName("NotificationIdentifier", object: nil)
self.navigationController?.pushViewController(landingView, animated: true)
}在我的新闻控制器中
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "methodOfReceivedNotification:", name:"NotificationIdentifier", object: nil)
}
func methodOfReceivedNotification(notification: NSNotification){
}
override func viewWillDisappear(animated: Bool) {
NSNotificationCenter.defaultCenter().removeObserver(self, name: "NotificationIdentifier", object: nil)
}发布于 2015-10-26 18:51:00
您调用了此方法
NSNotificationCenter.defaultCenter().postNotificationName("NotificationIdentifier", object: nil)在你的观察者被创建之前。因此,请在此方法self.navigationController?.pushViewController(landingView, animated: true)完成后发布您的通知。你可以参考这篇文章:
Completion handler for UINavigationController "pushViewController:animated"?
希望这能有所帮助。
https://stackoverflow.com/questions/33342939
复制相似问题