[英]How to hide the tab bar item?
我是這個 iphone 開發的新手。我創建了一個包含 6 個選項卡的選項卡欄應用程序,這是在 appdelegaate 文件 didfinishlaunching 中創建選項卡欄 controller 的代碼
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];
現在我的問題是在一個人登錄后,即登錄頁面中的登錄按鈕 onclick 我想隱藏兩個選項卡欄項目,即注冊頁面和登錄頁面,需要將注銷頁面和我的個人資料頁面與選項卡欄一起使用包括 fetch card 和 card avalable 任何人都可以建議我這樣做的方法嗎?
您可以通過編輯標簽欄的視圖控制器數組來添加和刪除標簽欄上的項目。
NSMutableArray newArrayOfItems = [[NSMutableArray alloc] initWithArray:self.tabBarController items]];
[newArrayOfItems removeObjectAtIndex:indexOfUnneededItem];
[self.tabBarController setItems:newArrayOfItems animated:true];
[newArrayOfItems release];
在您的示例中,為了響應您的評論,只要您導入您的應用程序委托 header,以下代碼就會起作用。
NSMutableArray newArrayOfItems = [[NSMutableArray alloc] initWithArray: [[[UIApplication sharedApplication] delegate].tabBarController items]];
[newArrayOfItems removeObjectAtIndex:indexOfUnneededItem];
[[[UIApplication sharedApplication] delegate].tabBarController setItems:newArrayOfItems animated:true];
[newArrayOfItems release];
您可以在推送視圖 controller 之前設置hidesBottomBarWhenPushed
屬性。示例代碼如下:
LoginController *lc = [[LoginController alloc] initWithNibName:nil bundle:nil];
lc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:lc animated:YES];
[lc release];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.