gpt4 book ai didi

iphone - 点击 tabBar 时转到 rootView

转载 作者:可可西里 更新时间:2023-11-01 05:02:27 35 4
gpt4 key购买 nike

我使用了基于 View 的应用程序,因为我以编程方式生成了 TabBar。问题是:

我有一个iPhone应用程序,其中我有2个带有tabbarcontroller的tabiTems。inside tabbarcontroller每个viewController是一个导航 Controller 。选择第二个标签时,我有一个 View Controller 。当我选择另一个 View 的按钮时,我正在按下另一个 View self.navigation controller 的 Controller 。在那个 viewcontroller 中,我正在插入并像那样进行。但问题是当我再次选择 tabitem 时,那里显示了 pushviewcotrooller。但是当我选择选项卡时,我再次需要那个 rootview

我在 AppDelegate.m 中的代码是:

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

UINavigationController *nc1;
nc1 = [[UINavigationController alloc] init];

UIViewController *viewController1 = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
nc1.viewControllers = [NSArray arrayWithObjects:viewController1, nil];





UINavigationController *nc2;
nc2 = [[UINavigationController alloc] init];

UIViewController *viewController2 = [[[secondview alloc] initWithNibName:@"secondview" bundle:nil] autorelease];
nc2.viewControllers = [NSArray arrayWithObjects:viewController2, nil];


self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:nc1,nc2,nil];
self.window.rootViewController=self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}

最佳答案

也许你正在寻找这个:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
int tabitem = tabBarController.selectedIndex;
[[tabBarController.viewControllers objectAtIndex:tabitem] popToRootViewControllerAnimated:YES];
}

关于iphone - 点击 tabBar 时转到 rootView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12142755/

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