gpt4 book ai didi

ios - PushViewController 与 tabBarController 不工作

转载 作者:行者123 更新时间:2023-11-28 22:31:29 26 4
gpt4 key购买 nike

我有一个 tabBar 应用程序。其中一个选项卡有一个 rootviewcontroller,它创建一个 UITableView 并将其添加到 subview 。当用户单击 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;
}

在我的 subview didSelectRowAtIndexPath 方法中:

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

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

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

}

最佳答案

您需要为每个选项卡创建一个单独的导航 Controller

关于ios - PushViewController 与 tabBarController 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17303700/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com