0

我有一个 tabBar 应用程序。其中一个选项卡有一个 rootviewcontroller,它创建一个 UITableView 并将其添加到子视图中。当用户单击 UITableView 中的单元格时,我想推送一个新的 rootviewcontroller,但我无法让它工作。

在我的 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;
}

在我的子视图中 didSelectRowAtIndexPath 方法:

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

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

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

}
4

1 回答 1

4

对于每个选项卡,您需要创建一个单独的导航控制器

于 2013-06-25T17:32:27.077 回答