我要么是大脑受损,要么是对 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。
所以有什么想法为什么它告诉我我一开始没有添加和观察者?