通知传值三步
2020-11-12 本文已影响0人
LazyJ
发送通知:
let dic = ["参数名": "参数"]
NotificationCenter.default.post(name: NSNotification.Name("notiname"), object: self, userInfo: dic)
监听通知:
NotificationCenter.default.addObserver(self, selector: #selector(notiaction(note:)), name: NSNotification.Name(rawValue:"notiname"), object: nil)
@objc func notiaction(note: NSNotification){
print(note.userInfo! as NSDictionary)
}
释放监听通知:
NotificationCenter.default.removeObserver(self)