Every time a user changes a tab, for the selected tab I want to push it to its top level controller. I have implemented the delegate method for the Tabbarcontroller like this:
- (void) tabBarControler:(UITabBarController *)tabBarController didSelectViewController:(UIViewController*)viewController{
[[self navigationController] popToRootViewControlle开发者_StackOverflowr Animated:NO];
}
This does nto seem to work but I can confirm the method is being called every time I change tabs
Based on your code, it looks like a simple misspelling. The correct method is [[self navigationController] popToRootViewControllerAnimated:NO]
(you had an extra space). Also, tabBarController is misspelled, which would prevent the method from being called.
If that doesn't work, it's possible that [self navigationController]
might be wrong (depending on where you're calling the method from). If you're calling from your AppDelegate, it should probably be something like [tabBarController.selectedViewController.navigationController popToRootViewControllerAnimated:NO]
. Hope that helps.
精彩评论