2012-02-07 2 views
1

표준 테이블 응용 프로그램을 지금 작성했습니다. Window는 UINavigationController를 rootViewController로 가지고 있으며, UINavigationController는 rootViewController와 함께 커스텀 UITableController로 초기화되었다.iOS의 기본 테이블 프로그램 - 응용 프로그램 대리인의 데이터를 다시로드하도록 내 테이블에 어떻게 알릴 수 있습니까?

내 응용 프로그램 테이블 데이터가 시간이 지남에 따라 변경됩니다. 보류 상태에서 애플리케이션을 열면 내 데이터가 오래되었습니다. applicationWillEnterForeground에서 데이터를 업데이트하려면 어떻게해야합니까? 나는 어색한 무엇인가 시도했다.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 
    self.window.backgroundColor = [UIColor whiteColor]; 
    HabitsTable* vc = [[HabitsTable alloc] init]; 
    [vc initCoreData]; 
    UINavigationController* nav = [[UINavigationController alloc]  initWithRootViewController:vc]; 
    self.window.rootViewController = nav; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

- (void)applicationWillEnterForeground:(UIApplication *)application 
{ 
     [[[[self window] rootViewController] navigationController] rootViewController] 
} 

그러나 놀랄만한 일은하지 않는다. 내 UITableController 얻을 방법을 잘 모르겠어요?

답변

1

NSNotificationCenter을 사용하는 것이 좋습니다. 클래스 here을 사용하는 좋은 예를 볼 수 있습니다.

UINavigationController *navController = (UINavigationController*)[[self window] rootViewController]; 
HabitsTable *tableView = (HabitsTable*)[navController topViewController]; 
+0

남자, 즉 도움이되었다 : – techgnosis

0

나는 당신의 가까운 시도를 생각합니다. NSNotificationCenter에 대해 배우면 아마 지금 내 전체 응용 프로그램을 리팩토링 할 수 있습니다. 감사!
+0

아, topViewController. 그게 내가 찾던 것 같아. NSNotificationCenter를 대신 사용하는 것이 좋을 것입니다. NSNotificationCenter를 사용하면 훨씬 적은 코드 중복이 발생할 수 있기 때문입니다. – techgnosis

+0

아마도 좋은 생각 일 수 있습니다. – Jaybit

관련 문제