2011-01-20 2 views
7

저는 아주 간단한 질문을 가지고 있지만, 여전히 코코아 주위에있는 길을 찾고 있습니다. Xcode에서 생성 된 일반 rootViewController 응용 프로그램이 있습니다. AppDelegate에는 데이터베이스를 업데이트하는 기능이 있습니다. 실행 중에 푸시 메시지가 들어 오면 (didReceiveRemoteNotification :) 데이터가 업데이트됩니다.AppDelegate에서 tableView를 다시로드하십시오.

하지만 RootViewController가 객체를 업데이트하고 함수 (즉, 함수) 인 테이블을 다시로드하라는 메시지를 처리하려면 어떻게해야합니까?

답변

20

당신은 NSNotificationCenter를 사용하여 rootViewController에서 NSNotificationCenter Class Reference

볼 수있다 '

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateView:) name:@"updateRoot" object:nil]; 

다음과 같은 방법 추가의 viewDidLoad를, 다음을 추가하여 AppDelegate에서

- (void)updateView:(NSNotification *)notification { 
    [myTableView reloadData]; 
} 

를' s didReceiveRemoteNotification, 다음을 추가하십시오.

[[NSNotificationCenter defaultCenter] postNotificationName:@"updateRoot" object:nil]; 
+0

내가 시도한 것보다 훨씬 간단하고 추가 기능을 위해 매우 유용하기 때문에 물어볼 가치가있었습니다. 대단히 감사합니다! –