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"])
网友评论