2012-03-12 44 views
0

在AViewController中我做了下一件事。我有一个崩溃。为什么我的班级收到通知?

[self.navigationController popViewControllerAnimated:NO]; 
[[AppDelegate delegate].tabBarController setSelectedIndex:1]; 

AViewController将被释放并且BViewController将会出现(它是第一个标签)。

我有一个崩溃。

1)AViewController卡列斯的dealloc

2)BViewController发出通知

3)我得到崩溃AViewController

的onRotation方法为什么AViewController收到ntf_onRotation通知?我添加了removeObserver方法。

我的班

@implementation AViewController 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(onRotation:) 
              name:@"ntf_onRotation" 
              object:nil]; 
} 

-(void) viewDidUnload 
{ 
[super viewDidUnload]; 
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"ntf_onRotation" object:nil]; 
} 

- (void)dealloc 
{ 
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"ntf_onRotation" object:nil]; 
[super dealloc]; 
} 

@end 

@implementation BViewController 

- (void)viewDidAppear:(BOOL)animated 
{ 
[super viewDidAppear:animated]; 
[[NSNotificationCenter defaultCenter] postNotificationName:@"ntf_onRotation" object:nil]; 
} 

- (void)viewWillAppear:(BOOL)animated 
    { 
    [super viewWillAppear:animated]; 
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ntf_onRotation" object:nil]; 
} 
@end 
+0

你检查AViewController所有其他引用?如果AViewController仍然收到通知,那么它意味着AViewController是活的。 – beryllium 2012-03-12 16:20:04

+0

我添加NSLog到dealloc。我看到它被称为。这意味着AViewController的保留计数等于零。 – Voloda2 2012-03-13 16:11:58

回答

0

这应该删除所有观察员包括任何未知的:

[[NSNotificationCenter defaultCenter] removeObserver:self]; 
相关问题