我在 a 上有两个选项卡UITabBarController,我都注册了NSNotificationCenter,我的问题是我没有在隐藏选项卡上收到通知(即它还没有被调用viewDidAppear:)。我的想法是不在屏幕上(即隐藏)的控制器不响应NSNotifications. 我可以用不同的方式做事,这不是问题,但我只是想验证为什么隐藏的选项卡没有收到通知,以防我遗漏了其他东西并且它实际上应该工作......
编辑:
@Fab1n为我指出了正确的方向,我错误地习惯于viewWillDisappear:移除观察者,所以当视图消失时不再监听通知。我会把它移到dealloc.
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter removeObserver:self];
}
变成:
- (void)dealloc {
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter removeObserver:self];
}
非常感激。