【发布时间】:2011-05-11 09:12:18
【问题描述】:
我要么是大脑受损,要么是我对 NSNotificationCenter 缺乏了解
问题是,如果我创建一个观察者并且在下一行中会尝试像这样删除它:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(removeAllVisibleMapViews) name:@"ClearVisibleMaps" object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self forKeyPath:@"ClearVisibleMaps"];
我明白了
*** Terminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer <MyApp 0x592db70> for the key path "ClearVisibleMaps" from <NSNotificationCenter 0x4e0fbb0> because it is not registered as an observer.'
我一行一行地添加和删除观察者只是为了说明一点。在我的代码中,我将在 dealloc 中使用 remove。
那么任何想法为什么它确实告诉我我没有首先添加和观察者?
【问题讨论】:
标签: iphone objective-c ios nsnotificationcenter