PushViewController with tabBarController not working

南笙酒味 提交于 2019-12-13 05:08:33

问题


I have a tabBar application. One of the tabs has a rootviewcontroller that creates a UITableView and adds it to the subview. When a user clicks a cell in the UITableView I want to push a new rootviewcontroller but I cant get it to work.

In my appDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 {
    //Create the window
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    //Create the UIViewCOntrollers for each tab
    _viewController1 = [[[LocavoreRetroFirstViewController alloc] initWithNibName:@"LocavoreRetroFirstViewController" bundle:nil] autorelease];
    _viewController2 = [[[LocavoreRetroSecondViewController alloc] initWithNibName:@"LocavoreRetroSecondViewController" bundle:nil] autorelease];
    UIViewController *viewController3 = [[[LocavoreRetroThirdViewController alloc] initWithNibName:@"LocavoreRetroThirdViewController" bundle:nil] autorelease];
    _viewController4 = [[[LocavoreRetroFourthViewController alloc] initWithNibName:@"LocavoreRetroFourthViewController" bundle:nil] autorelease];
    UIViewController *viewController5 = [[[LocavoreRetroFifthViewController alloc] initWithNibName:@"LocavoreRetroFifthViewController" bundle:nil] autorelease];


    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController1];
    //[_viewController1 release];

     NSArray* controllers = [NSArray arrayWithObjects:navigationController, _viewController2, viewController3, _viewController4, viewController5, nil];

    //Create the tab controller
    _tabBarController = [[[UITabBarController alloc] init] autorelease];
    [_tabBarController setViewControllers:controllers];


    //Initialize the tab controller with the views
//    _tabBarController.viewControllers = @[_viewController1, _viewController2,
//    viewController3, _viewController4, viewController5];

    //Set the window to the tabcontroller view and make it visible
    _window.rootViewController = _tabBarController;
    _tabBarController.delegate=self;
    [_window makeKeyAndVisible];

    return YES;
}

In my subview didSelectRowAtIndexPath method:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{   

    RecipePageController *recipePageController = [[RecipePageController alloc] initWithNibName:@"RecipePageController" bundle:nil];

    [self.navigationController pushViewController:recipePageController animated:YES];
    [recipePageController release];

}

回答1:


For each tab you need to create a separate navigation controller



来源:https://stackoverflow.com/questions/17303700/pushviewcontroller-with-tabbarcontroller-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!