我使用了基于视图的应用程序&因为我以编程方式生成TabBar。问题是:
我有一个Iphone应用程序,其中有两个带有tabbarcontroller.Inside的选项卡项每个视图控制器都是一个导航controller.when选择第二个选项卡我有一个视图controller.when在上面选择一个按钮,我正在将另一个视图控制器推送到该视图控制器中的self.navigation controller.and我像that.But一样按下并运行,问题是当我再次选择选项卡项时,pushedviewcotrooller显示为there.but当我选择该选项卡时,我需要再次使用该根视图
我在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;
}发布于 2012-08-27 21:27:17
也许你正在寻找这个:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
int tabitem = tabBarController.selectedIndex;
[[tabBarController.viewControllers objectAtIndex:tabitem] popToRootViewControllerAnimated:YES];
}发布于 2016-04-13 18:08:27
在swift中,你可以在你的UITabBarController类中这样做:
override func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) {
let rootView = self.viewControllers![self.selectedIndex] as! UINavigationController
rootView.popToRootViewControllerAnimated(false)
}发布于 2012-08-27 21:30:45
我相信你需要使用这两种方法:
UINavigationController:-popToRootViewControllerAnimated
UITabBarControllerDelegate: tabBarController:didSelectViewController:我在自己的程序中使用的方法是在屏幕上显示根视图控制器时只显示选项卡栏。
https://stackoverflow.com/questions/12142755
复制相似问题