繁体   English   中英

来自NSObject子类的iOS NSNotificationCenter addObserver

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM