Question

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];

}
Was it helpful?

Solution

For each tab you need to create a separate navigation controller

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top