2012-03-12 2 views
0

AViewController에서 다음 작업을 수행합니다.충돌이 있습니다. 수업이 알림을받는 이유는 무엇입니까?

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

AViewController가 할당 해제되고 BViewController가 표시됩니다 (첫 번째 탭).

충돌이 있습니다.

1) AViewController 호출되어 할당 해제

2) BViewController 보내는 통지

3) 내가 왜 AViewController가 ntf_onRotation 알림을받을 않습니다

AViewController

의 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

+0

dealloc에 ​​NSLog를 추가했습니다. 나는 그것이 부름 받았다는 것을 알았다. AViewController의 보유 개수가 0과 같습니다. – Voloda2

답변

0

이 알 수없는 사람을 포함한 모든 관찰자를 제거해야합니다 :

[[NSNotificationCenter defaultCenter] removeObserver:self];