Reputation: 13286
- (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];
}
}
Upvotes: 0
Views: 441
Reputation: 4664
Why not just put the reload data call in the viewDidAppear method of the SavedViewController class?
Upvotes: 2
Reputation: 10065
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.
Upvotes: 1
Reputation: 10397
Dot notation would clean up some of the bracket forest, but that's all I can think of.
Upvotes: 1