jjzjj

addObserverForName

全部标签

iphone - 为什么不从 NSNotificationCenter :addObserverForName:usingBlock get called 中删除观察者

我对为什么在以下代码中从未删除观察者感到困惑。在我的viewDidAppear中,我有以下内容:-(void)viewDidAppear:(BOOL)animated{idgpsObserver=[[NSNotificationCenterdefaultCenter]addObserverForName:FI_NOTES[kNotificationsGPSUpdated]object:nilqueue:[NSOperationQueuemainQueue]usingBlock:^(NSNotification*note){NSLog(@"runonce,andonlyonce!");[

iphone - 为什么不从 NSNotificationCenter :addObserverForName:usingBlock get called 中删除观察者

我对为什么在以下代码中从未删除观察者感到困惑。在我的viewDidAppear中,我有以下内容:-(void)viewDidAppear:(BOOL)animated{idgpsObserver=[[NSNotificationCenterdefaultCenter]addObserverForName:FI_NOTES[kNotificationsGPSUpdated]object:nilqueue:[NSOperationQueuemainQueue]usingBlock:^(NSNotification*note){NSLog(@"runonce,andonlyonce!");[

ios - 使用 addObserverForName :usingBlock 时移除 Observer

我有以下代码在加载View时添加观察者。-(void)viewDidLoad{[superviewDidLoad];[[NSNotificationCenterdefaultCenter]addObserverForName:@"com.app.livedata.jsonupdated"object:nilqueue:[NSOperationQueuemainQueue]usingBlock:^(NSNotification*notif){NSLog(@"JSONUPDATED");}];}这很好。但是,当卸载View并且我确认dealloc被调用时,通知仍在触发。好像没有关闭这个观察

ios - 使用 addObserverForName :usingBlock 时移除 Observer

我有以下代码在加载View时添加观察者。-(void)viewDidLoad{[superviewDidLoad];[[NSNotificationCenterdefaultCenter]addObserverForName:@"com.app.livedata.jsonupdated"object:nilqueue:[NSOperationQueuemainQueue]usingBlock:^(NSNotification*notif){NSLog(@"JSONUPDATED");}];}这很好。但是,当卸载View并且我确认dealloc被调用时,通知仍在触发。好像没有关闭这个观察

ios - 正确管理addObserverForName :object:queue:usingBlock:

我对objective-c中的block还是个新手,想知道我的伪代码是否正确。我不确定只删除观察者是否足够,或者我是否必须调用removeObserver:name:object:-(void)scan{Scanner*scanner=[[Scanneralloc]init];idscanComplete=[[NSNotificationCenterdefaultCenter]addObserverForName:@"ScanComplete"object:scannerqueue:nilusingBlock:^(NSNotification*notification){/*dosom