美文网首页
通知中心:不同ViewController传递数据

通知中心:不同ViewController传递数据

作者: Dove_Q | 来源:发表于2016-09-01 19:50 被阅读14次

ViewController

override func viewDidLoad() {
        super.viewDidLoad()
        
        //通知
        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(didNotif(_:)), name: "notifName", object: nil)
    }
    
    func didNotif(sender: NSNotification) {
        print(sender.name)  //通知名称
        print(sender.userInfo) //附加的信息
        print(sender.object) //发送者
        
        label.text = sender.userInfo!["info"] as! String
    }

OtherViewController

NSNotificationCenter.defaultCenter().postNotificationName("notifName", object: nil, userInfo: ["info":"xxx"])

相关文章

网友评论

      本文标题:通知中心:不同ViewController传递数据

      本文链接:https://www.haomeiwen.com/subject/xwchettx.html