Nik*_*ure 2 observers selector nsnotificationcenter notificationcenter swift
func addObserver(_ observer: Any, selector aSelector: Selector, name aName: NSNotification.Name?, object anObject: Any?)
Run Code Online (Sandbox Code Playgroud)
此函数需要观察者成为某个对象,但需要将静态方法设置为选择器.
这个答案解释了当选择器是实例方法时如何设置选择器和观察者.
我们需要设置YourClass.self
为观察者.通过这种方式 -
NotificationCenter.default.addObserver(YourClass.self, selector: #selector(YourClass.yourStaticMethod), name: NSNotification.Name.BlahBlah, object: nil)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
563 次 |
最近记录: |