首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSNotificationCenter不工作

NSNotificationCenter不工作
EN

Stack Overflow用户
提问于 2015-10-26 18:02:10
回答 1查看 651关注 0票数 1

我想在Swift 2.0中使用NSNotificationCenter .They do not call来调用一个方法。我是Swift的新人。请帮帮忙。任何帮助都会得到重视。

代码语言:javascript
复制
    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)
    }

在我的新闻控制器中

代码语言:javascript
复制
    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)

    }
EN

回答 1

Stack Overflow用户

发布于 2015-10-26 18:51:00

您调用了此方法

代码语言:javascript
复制
NSNotificationCenter.defaultCenter().postNotificationName("NotificationIdentifier", object: nil)

在你的观察者被创建之前。因此,请在此方法self.navigationController?.pushViewController(landingView, animated: true)完成后发布您的通知。你可以参考这篇文章:

Completion handler for UINavigationController "pushViewController:animated"?

希望这能有所帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33342939

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档