TableView in NavigationBar and Tabbar Switch Between Tabs Gets Bad Access
I'm building an app that combines tabbar and navigation bar. In one of tabs, I have a UIButton and by touching it, I push a Tableview into stack of navigationcontroller. Then, without returning to the root view controller manually by pressing Back buttons I change to another tab from tabbar and when I com开发者_Python百科e back to the tab with the tableview inside, I get bad access error.
I've already tried popping the tableview from navigation controllers stack, or not releasing the tableview but I could't make it.
Thanks...
Assuming you've created your tabBar and Navigation Controllers in the AppDelegate, you can code your app to return each tab to the root view when it is selected.
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if (viewController == firstViewNavigationController) {
[firstViewNavigationController popToRootViewControllerAnimated:NO];
} else if (viewController == secondViewNavigationController) {
[secondViewNavigationController popToRootViewControllerAnimated:NO];
}
}
I am using this and it is working fine in my app. I am releasing my Navigation Controllers in the dealloc method. I have also made my AppDelegate conform to the UITabBarDelegate protocol.
精彩评论