发送通知
let dic = ["name":"hello"];NSNotificationCenter.defaultCenter().postNotificationname("NotificationIDentifIEr",object: dic)
接收通知
NSNotificationCenter.defaultCenter().addobserver(self,selector: "getMyname:",name:"NotificationIDentifIEr",object: nil)
删除通知
NSNotificationCenter.defaultCenter().removeObserver(self,name: "NotificationIDentifIEr",object: nil)NSNotificationCenter.defaultCenter().removeObserver(self)
func getMyname(notification:NSNotification){ //获取词典中的值 let name = notification.object?.valueForKey("name") as? String //通知的名称 let nameNotification = notification.name //notification.userInfo 接收object 对象 一些信息 例如入键盘的一些信息 print(nameNotification) print(name); }总结
以上是内存溢出为你收集整理的swift2.0 NSNotificationCenter 使用和传值全部内容,希望文章能够帮你解决swift2.0 NSNotificationCenter 使用和传值所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)