2010-05-18 2 views
1

"속성"이라는 다른 클래스 중 하나에서 "WriteIt_MobileAppDelegate"라는 다른 클래스에있는 테이블 뷰를 다시로드하고 싶습니다. NSNotificationCenter 클래스를 통해이 작업을 시도했습니다. 로그는 호출되지만 테이블은 업데이트되지 않습니다.iPhone - 다른 클래스의 선택기 실행

Properties.h :

[[NSNotificationCenter defaultCenter] postNotificationName:@"NameChanged" 
       object:[WriteIt_MobileAppDelegate class] 
       userInfo:nil]; 

WriteIt_MobileAppDelegate.m

- (무효)로 awakeFromNib {

[NSNotificationCenter defaultCenter] addObserver : 자기 선택기 : @ 선택기 (reloadItProperties :) name : @ "NameChanged"object : self];

}

- (void) reloadItProperties: (NSNotification *)notification { 

NSLog(@"Reloading Data"); //this gets called 
[[self navigationController] dismissModalViewControllerAnimated:YES]; 
[self.navigationController popToRootViewControllerAnimated:YES]; 
[self.tblSimpleTable reloadData]; 
[self.tblSimpleTable reloadSectionIndexTitles]; 
// but the rest doesn't 
} 

은 내가 잘못 여기서 뭐하는 거지? 당신이 object 매개 변수의 잘못된 사용과 같은

+0

기본 데이터가 reloadItProperties에 도달하기 전에 업데이트되었는지 확인 했습니까? 해당 NSLog 줄에 업데이트 된 데이터 로깅을 추가하십시오. 또한 postNotificationName에서'[WriteIt_MobileAppDelegate class] 대신'self'를 원할 수도 있습니다. – DyingCactus

+0

예, 데이터가 변경됩니다. "자기"를 추가하는 것은 아무 것도하지 않았고 방금 NSLog가 오지 못하게 막았습니다. 선택기를 어떻게 든 다르게 호출 할 수 있습니까? – Pripyat

+2

문제는 아니지만 postNotificationName에서 자아를 원할 수도 있습니다. 그러나 ChriB가 언급 한 것처럼'addObserver'에서 object 매개 변수를 self에서 nil로 변경해야합니다. 자기가 있으면 자기 (WriteIt)의 알림 만 듣게됩니다. 어쨌든 reloadItProperties가 왜 호출되는지 설명하지는 않습니다. NameChanged에 대한 postNotificationName 이외의 reloadItProperties를 호출하는 다른 코드가 있습니까? – DyingCactus

답변

2

이 보인다 :

addObserver:selector:name:object:


그 통지 관찰자가 원하는 을받는 객체 notificationSender을;
즉,이 발신자가 보낸 알림 만이 관찰자 에게 전달됩니다. nil을 전달하면 알림 센터에서 알림을 보낸 사람을 관찰자에게 전달할지 여부를 결정하기 위해 을 결정하지 않습니다.

+0

나는 그렇게 생각하지 않는다. [WriteIt_MobileAppDelegate class]는 NSLog를 토글하는 유일한 객체이다. 선택기를 토글하여 테이블 뷰를 업데이트하는 다른 방법이 있습니까? – Pripyat

관련 문제