1

I've got your standard table application built right now. Window has a UINavigationController as its rootViewController, and that UINavigationController was initialized with its rootViewController as my custom UITableController.

My applications table data changes over time. If I open my application up from a suspended state then my data is stale. How do I get applicationWillEnterForeground to update my data? I tried something awkward like

- (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]
}

But, no surprise, that doesn't work. I'm not sure how to get at my UITableController?

techgnosis
  • 1,879
  • 2
  • 17
  • 19

2 Answers2

1

I'd recommend using the NSNotificationCenter. You can see a nice example of how to use the class here.

Community
  • 1
  • 1
Nathanial Woolls
  • 5,231
  • 24
  • 32
  • Man, that was helpful. Learning about NSNotificationCenter will probably cause me to refactor my whole application now. Thanks! – techgnosis Feb 07 '12 at 22:04
0

I believe your close try:

UINavigationController *navController = (UINavigationController*)[[self window] rootViewController];
HabitsTable *tableView = (HabitsTable*)[navController topViewController];
Jaybit
  • 1,864
  • 1
  • 13
  • 20
  • Ah, topViewController. That is most likely what I was looking for. I think I'm going to use NSNotificationCenter instead, since that will likely lead to much less code duplication. – techgnosis Feb 07 '12 at 22:05