IOS 通知

ios 的通知

swift2.3

1
2
3
4
5
6
7
8
9
10
11
NSNotificationCenter.defaultCenter().postNotificationName("HomRefresh", object: data)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "homeRefresh:", name: "HomRefresh", object: nil)//接受消息
func homeRefresh(Notification:NSNotification){
// 传递的各种类型的数据
let data = Notification.object as XX
}

swift 3 里面写法变了 更新下写法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "namexxx"), object: "数据", userInfo: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.collcetNotifiaction(_:)), name: NSNotification.Name(rawValue:VideoCollectMessage), object: nil)
/// 收藏 消息接受
func collcetNotifiaction(_ sender:Notification) {
let cell = self.tableView.cellForRow(at: IndexPath(row: 0, section: 2)) as? VideoNewPageOtherViewMenuCell
if cell != nil{
DispatchQueue.main.async {
cell!.setMenuBtnStatus(3, status: true)
}
}
}
Author

陈昭

Posted on

2016-10-18

Updated on

2021-12-27

Licensed under

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

Kommentare

You forgot to set the shortname for Disqus. Please set it in _config.yml.