我是这个iphone开发的新手。我创建了一个标签栏应用程序,它包含6个标签 这是appdelegaate文件中的标签栏控制器创建的代码didfinishlaunching
UIViewController *viewController1 = [[[cardsAvailable1 alloc]
initWithNibName:@"cardsAvailable1" bundle:nil] autorelease];
UIViewController *viewController2 = [[[fetchcard1 alloc]
initWithNibName:@"fetchcard1" bundle:nil] autorelease];
UIViewController *viewController3 = [[[registration alloc]
initWithNibName:@"registration" bundle:nil] autorelease];
UIViewController *viewController4 = [[[logintab alloc]
initWithNibName:@"logintab" bundle:nil] autorelease];
UIViewController *viewController5 = [[[registration alloc]
initWithNibName:@"logout" bundle:nil] autorelease];
UIViewController *viewController6 = [[[logintab alloc]
initWithNibName:@"myprofile" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:
[[[UINavigationController alloc] initWithRootViewController:viewController1] autorelease],
[[[UINavigationController alloc] initWithRootViewController:viewController2] autorelease],
[[[UINavigationController alloc] initWithRootViewController:viewController3] autorelease],
[[[UINavigationController alloc] initWithRootViewController:viewController4] autorelease],
[[[UINavigationController alloc] initWithRootViewController:viewController5] autorelease],
[[[UINavigationController alloc] initWithRootViewController:viewController6] autorelease],
nil];
self.tabBarController.selectedIndex = 3;
self.window.rootViewController = self.tabBarController;
[self.window addSubview:self.tabBarController.view];
[self.window makeKeyAndVisible];
现在我的问题是在一个人登录后,即点击登录页面中的登录按钮我想要隐藏两个标签栏项目,即注册页面和登录页面,并需要带有登出页面和myprofile页面标签栏包括提取卡和可用的卡可以任何人建议我这样做的方法吗?
答案 0 :(得分:3)
您可以通过编辑标签栏的视图控制器数组来添加和删除标签栏上的项目。
NSMutableArray newArrayOfItems = [[NSMutableArray alloc] initWithArray:self.tabBarController items]];
[newArrayOfItems removeObjectAtIndex:indexOfUnneededItem];
[self.tabBarController setItems:newArrayOfItems animated:true];
[newArrayOfItems release];
在您的示例中,为了回复您的评论,只要您导入应用代理标题,以下代码就会有效。
NSMutableArray newArrayOfItems = [[NSMutableArray alloc] initWithArray: [[[UIApplication sharedApplication] delegate].tabBarController items]];
[newArrayOfItems removeObjectAtIndex:indexOfUnneededItem];
[[[UIApplication sharedApplication] delegate].tabBarController setItems:newArrayOfItems animated:true];
[newArrayOfItems release];
答案 1 :(得分:1)
您可以在推送视图控制器之前设置hidesBottomBarWhenPushed
属性。下面是示例代码:
LoginController *lc = [[LoginController alloc] initWithNibName:nil bundle:nil];
lc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:lc animated:YES];
[lc release];