swift2.0 NSNotificationCenter 使用和传值

swift2.0 NSNotificationCenter 使用和传值,第1张

概述发送通知 let dic = ["name":"hello"];NSNotificationCenter.defaultCenter().postNotificationName("NotificationIdentifier", object: dic) 接收通知 NSNotificationCenter.defaultCenter().addObserver(self, selector:

发送通知

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 使用和传值所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1083862.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存