2011-05-04 65 views
2

我目前在我的應用程序委託中有一個UINavigationController,我在其中推送ViewController以進行登錄。如果登錄成功,我想要使用導航控制器創建一個UITabBarController作爲第一個Tab,其根控制器是我創建的UIViewController。使用UINavigationBarController以編程方式添加UITabBarController作爲第一個選項卡到現有的導航控制器

我的第一個UINavigationController的RootViewController實際上充當logincontroller的委託,所以如果用戶正確登錄,它會調用我的RootViewController中的一個方法,然後我將該方法推送到堆棧上的UITabBarController。這裏是我的代碼:

UITabBarController *tbController = [[UITabBarController alloc] init]; 
    FileBrowserViewController *fileController = [[FileBrowserViewController alloc] init]; 
    fileController.pathToFileDB = pathToDBUnzipped; 
    fileController.parentId = @"0"; 

    UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:fileController]; 

    NSMutableArray *aViewControllersArray = [[NSMutableArray alloc] initWithCapacity:2]; 
    [aViewControllersArray addObject:navController]; 
    [navController release]; 

    [tbController setViewControllers:aViewControllersArray]; 

    [self.navigationController pushViewController:tbController animated:YES]; 

    [tbController release]; 

現在,它都工作正常。除了2件事。這裏是屏幕截圖: My iPHone

1)我不能看到任何uitabbar項目。我如何設置圖片和每個標籤的文字? 2)我不想要那頂黑色的酒吧。我只想用撤銷按鈕打開1個酒吧。我如何刪除額外的欄?

感謝您的幫助!

回答

2

隱藏上述黑條使用 -

[self.navigationController setNavigationBarHidden:TRUE]; 

設置標籤欄項目使用 -

系統項目 -

UITabBarItem *firstItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:0]; 

定製項目 -

UITabBarItem *firstItem = [[UITabBarItem alloc] initWithTitle:@"title" image:[UIImage imageNamed:@""] tag:0]; 

[navController setTabBarItem:firstItem]; 
+0

鏈接被破壞(2012年12月28日) – CCC 2012-12-28 08:13:48

0

這是一個關於如何結合標籤欄,導航欄和/或表格視圖的好視頻。

http://www.youtube.com/watch?v=LBnPfAtswgw

如果您不希望您註冊屏幕有一個標籤欄控制器,那麼你將不得不將其作爲一個模式視圖(因爲標籤欄是你的根視圖控制器)。這可以通過presentModalViewController:animated:方法完成。你可以找到有關信息:

http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html%23//apple_ref/doc/uid/TP40007457-CH111-SW1

我希望幫助。如果您有任何其他問題,請告訴我!

乾杯,埃文。

0

嗨朋友,頂欄是狀態欄。你可以set.statusbar hidden = yes; 或從plist中改變,當你打開你的plist有隱藏它的選項,

6

當我同時具有UINavigationController和UITabbarController時,我總是遵循這種方法:
您需要從基於視圖的應用程序開始。然後在你的appDelegate文件中創建一個UITabbarController。

Appdelegate.h 

UITabBarController *tabBarController; 
// set properties 

Appdelegate.m 

// Synthesize 

tabBarController = [[UITabBarController alloc] init]; 
tabBarController.delegate=self; 

// Adding Search,Nearby,Map,AboutUs,Favorites Tabs to tabBarController 
Search * search = [[Search alloc] init]; 
UINavigationController *searchNav = [[UINavigationController alloc]  initWithRootViewController:search]; 

Nearby* nearby = [[Nearby alloc] init]; 
UINavigationController *nearbyNav = [[UINavigationController alloc] initWithRootViewController:nearby]; 

Map* map = [[Map alloc] init]; 
UINavigationController *mapNav = [[UINavigationController alloc] initWithRootViewController:map]; 

AboutUs* aboutUs = [[AboutUs alloc] init]; 
UINavigationController *aboutUsNav = [[UINavigationController alloc] initWithRootViewController:aboutUs]; 

Favorites* favorites = [[Favorites alloc] init]; 
UINavigationController *favoritesNav = [[UINavigationController alloc] initWithRootViewController:favorites]; 

NSArray* controllers = [NSArray arrayWithObjects:searchNav,nearbyNav,mapNav,aboutUsNav,favoritesNav, nil]; 
tabBarController.viewControllers = controllers; 

[window addSubview:tabBarController.view];  

您可以相應地管理在哪個選項卡中放置導航控制器或只有視圖控制器。

在上述各你所提到的視圖控制器的

然後需要實現

- (id)init {} 

,可以在其中設置選項卡名稱和圖像。

我總是遵循這種方法,它永遠不會失敗。標籤始終可見。您可以根據您的代碼進行更改。

相關問題