[英]IOS NSNotificationCenter addObserver from subclass of NSObject
我从AppDelegate
添加了一个观察者,并将此代码放入didFinishLaunchingWithOptiong
方法中。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
internetReachability = [Reachability reachabilityForInternetConnection];
[internetReachability startNotifier];
现在,我想将此addObserver
放入我的自定义类中,该类是NSObject
的子类?
编辑:
这是我的reachabilityChanged方法:
- (void) reachabilityChanged:(NSNotification *)note
{
NSLog(@"change");
}
我将此方法放在调用addObserver的同一类上
为了运行reachabilityChanged
方法,您需要按以下方式发布已在AppDelegate
注册的通知
[[NSNotificationCenter defaultCenter] postNotificationName:kReachabilityChangedNotification object:nil];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.