【发布时间】:2011-12-12 16:41:52
【问题描述】:
我对为什么在以下代码中从未删除观察者感到困惑。在我的 viewDidAppear 中,我有以下内容:
-(void)viewDidAppear:(BOOL)animated{
id gpsObserver = [[NSNotificationCenter defaultCenter]
addObserverForName:FI_NOTES[kNotificationsGPSUpdated]
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note){
NSLog(@"run once, and only once!");
[[NSNotificationCenter defaultCenter] removeObserver:gpsObserver];
}];
}
观察者永远不会被删除,并且每次发出通知时都会输出该语句。任何人都可以提供任何指导吗?
【问题讨论】:
标签: iphone ios objective-c-blocks nsnotifications nsnotificationcenter