0

我是这个 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 页面包括获取卡和可用卡,有人可以建议我一种方法吗?

4

2 回答 2

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];
于 2012-04-04T04:58:52.960 回答
1

您可以hidesBottomBarWhenPushed在推送视图控制器之前设置属性。有下面的示例代码:

LoginController *lc = [[LoginController alloc] initWithNibName:nil bundle:nil];
lc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:lc animated:YES];
[lc release];
于 2012-04-04T08:22:38.917 回答