我正在尝试运行以下代码,除非发送了 NSNotification
。我不知道如何将 NSNotification
放在 if 语句中:
if (!self.subViewControllerProv) {
self.subViewControllerProv = [[ProvViewController alloc] init];
}
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleNotification:) name:@"SomeNotification" object:nil];
回顾一下:如果观察到 NSNotification
消息,则 alloc
和 init
ProvViewController
如果没有,则不要't.
最佳答案
那么做这样的事情怎么样:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification) name:@"SomeNotification" object:nil];
然后
-(void) handleNotification {
//BOOL _hasBeenSent in your interface
_hasBeenSent = YES;
}
然后在你的代码中
if(_hasBeenSent) {
NSLog(@"The notification has been sent!");
}
关于ios - 如何在 if 语句中检查 NSNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15293261/