1 : 定义自己的通知、广播名.
struct NotificationHelper {
static let updateList = Notification.Name("updateList")
}
struct NotificationHelper {
static let updateList = Notification.Name("updateList")
}
2 : 提交一个通知. (在触发功能块处提交)
NotificationCenter.default.post(name: NotificationHelper.updateList, object: nil)
3 : 添加观察者 (在接受通知事件处添加 , 此处 headerClick 为刷新方法 )
NotificationCenter.default.addObserver(self, selector: #selector(headerClick) , name: NotificationHelper.updateList, object: nil)
本文介绍了如何在Swift中定义自定义的通知名称,提交通知,并添加观察者来接收这些通知。通过具体的代码实例,展示了通知机制的基本使用方法。
1万+

被折叠的 条评论
为什么被折叠?



