2010-10-28 26 views
0

我知道這已經在很多其他主題,博客,書籍,YouTube等等中討論過幾次了。但是,讓我解釋一下我的情況。我希望在應用程序打開時顯示一個用於登錄的Facebook連接按鈕。用戶登錄後,它會調出tabBarView。在我的應用程序委託中,我首先添加MainViewController,然後在那裏顯示了facebook連接登錄按鈕。然後在它登錄後,它添加tabBarViewController作爲它的子視圖。UITabBarController + UINavBarController

現在在這個tabBarViewController中我想讓它有2個選項卡。第一個標籤人,第二個是地圖。我想在人物標籤中添加一個navBar。因此,我在我的代碼所做的是以下幾點:

tabBarViewController = [[TabBarViewController alloc] init]; 
    mvc = [[MapViewController alloc] init]; 
    UIImage* mapIcon = [UIImage imageNamed:@"13-target.png"]; 
    mvc.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"Map" image:mapIcon tag:0] autorelease]; 

    tvc = [[TableViewController alloc] init]; 
    UIImage* peopleIcon = [UIImage imageNamed:@"112-group.png"]; 
    tvc.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"People" image:peopleIcon tag:0] autorelease]; 

    friendsNavController = [[FriendsNavController alloc] init]; 


    tabBarViewController.viewControllers = [NSArray arrayWithObjects: friendsNavController, tvc, mvc, nil]; 
    tvc.userInfo = _userInfo; 
    [self.tabBarViewController viewWillAppear:YES]; 
    [self.view addSubview:self.tabBarViewController.view]; 

現在的結果是,我有3個標籤欄,一個帶有導航欄,一用一表列表,一個是地圖。如何更改代碼以使導航欄和表格視圖位於一個標籤欄中?我在這裏做錯了什麼?

這裏是它的外觀在界面生成器:

alt text

回答

1

標籤欄控制器的視圖控制器應該只包含導航控制器和的MapViewController的。

TableViewController(tvc)將在導航控制器的viewControllers中,而不是在tabBarViewController中。撥打朋友的號碼initWithRootViewController:tvcNavController

所以你的數組應該只有2個項目(friendsNavController和mvc)的tabBarViewControllers。

此外,這將意味着navigationController有一個tabBar項而不是tableViewController。

+0

我仍然困惑我應該在哪裏調用initWithRootViewController? – aherlambang 2010-10-28 15:04:18

+0

在你上面的代碼示例中調用: friendsNavController = [[FriendsNavController alloc] init]; Try: friendsNavController = [[FriendsNavController alloc] initWithRootViewController:tvc]; – joebonniwell 2010-10-28 15:45:08

+0

我需要把什麼東西放在navcontroller中? – aherlambang 2010-10-28 17:05:53