- (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];
}
}
views:
251answers:
3
+1
A:
Dot notation would clean up some of the bracket forest, but that's all I can think of.
Chris McCall
2009-07-16 21:10:24
+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
2009-07-16 21:11:06
Objective C and every other programming language I know of short circuits.
Andrew Johnson
2009-07-16 21:15:05
Thanks for the heads up.
Kailoa Kadano
2009-07-16 21:16:56
+2
A:
Why not just put the reload data call in the viewDidAppear method of the SavedViewController class?
Lounges
2009-07-17 00:51:43