Swift开发:NSNotificationCenter 传值
在app开发过程中,需要使用到NSNotificationCenter传递数据 第一步: 注册通知
NSNotificationCenter.defaultCenter().addObserver(self,selector: "sendCMD:",name: "sendCMD",object: nil); sendCMD 是接受通知时的接受函数,名字是通知的key
func sendCMD(obj: NSNotification) { let da:String? = obj.object as! String;// hello
// da就是数据,发送什么类型的数据 da就定义什么类型
} 注意移除通知
deinit { NSNotificationCenter.defaultCenter().removeObserver(self); }
第二部:发送通知
NSNotificationCenter.defaultCenter().postNotificationName("sendCMD",object:"hello") (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |