views:

251

answers:

3
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {

  NSLog(@"switching views");
  if([viewController isKindOfClass: [UINavigationController class]] &&
     [[[viewController viewControllers] objectAtIndex: 0] isKindOfClass: [SavedViewController class]]) {

      NSLog(@"its a SavedViewController");
      [[[[viewController viewControllers] objectAtIndex: 0] tableView] reloadData];
  }

}
+1  A: 

Dot notation would clean up some of the bracket forest, but that's all I can think of.

Chris McCall
+1  A: 

Cocoa's big trade off is readability vs conciseness.

You're not that far off from what I would do:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  NSLog(@"switching views");
  if([viewController isKindOfClass: [UINavigationController class]]) {
      id first_view_controller = [viewController.viewControllers objectAtIndex:0];
      if ([first_view_controller isKindOfClass: [SavedViewController class]) {
          NSLog(@"its a SavedViewController");
          [first_view_controller.tableView reloadData];
      }  
   }
}

Edited: used dot notation in a couple of places per C. McCall

Edited again: looks like ObjC does short circuit.

Kailoa Kadano
Objective C and every other programming language I know of short circuits.
Andrew Johnson
Thanks for the heads up.
Kailoa Kadano
+2  A: 

Why not just put the reload data call in the viewDidAppear method of the SavedViewController class?

Lounges
I was wondering the same thing...
Kendall Helmstetter Gelner
Good call on second thought :)
Andrew Johnson