问题描述
我的应用有多个通知和观察者,可在用户添加或删除数据时刷新视图。
我应该为每种类型的数据交互使用通知和观察者吗?例如:
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "categoryAdded"),object: nil)
然后针对每个通知:
NotificationCenter.default.addObserver(self,selector: #selector(self.refresh),name: NSNotification.Name(rawValue: "categoryAdded"),object: nil)
NotificationCenter.default.addObserver(self,name: NSNotification.Name(rawValue: "transactionAdded"),name: NSNotification.Name(rawValue: "transactionDeleted"),name: NSNotification.Name(rawValue: "transactionEdited"),object: nil)
或者我可以只使用一个值:
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "dataUpdated"),object: nil)
然后使用一个观察者:
NotificationCenter.default.addObserver(self,name: NSNotification.Name(rawValue: "dataUpdated"),object: nil)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)