2011-01-27 20 views
1

我怎麼能推TabBarController到View?推TabBarController於查看

的應用程序是基於視圖。在應用程序中,我有一個帶TabBarController的XIB,並且我想將TabBar推到顯示屏上。我做了所有事情,現在我不知道自己做錯了什麼。

這裏是應該推TabBarController代碼:

- (void)showTabBar { 
TabBar *tbc = [[TabBar alloc] initWithNibName:@"TabBar" bundle:nil]; 
[self presentModalViewController:tbc animated:YES]; 
[tbc release]; 
} 

在這一刻沒有在XIB空視圖。所以當我運行這個代碼時,顯示器是白色的。還有TabBarController,我想在顯示屏上看到它。

感謝您的幫助。


UPDATE:

我應該說,這是兩個不同的班級。函數「showTabBar」所基於的類應該推送TabBarController。第二個類是TabBar。 TabBar是TabBarController的委託。

所以我已經修改了這樣的答案,但我曾經嘗試都:

[self presentModalViewController:tbc.tabBarController.view animated:YES]; 

現在的錯誤看起來是這樣的:

Incompatible Objective-C types 'struct UIView *', expected 'struct UIViewController *' when passing argument 1 of 'presentModalViewController:animated:' from distinct Objective-C type 

UPDATE:

嘿,錯誤已經消失。涼。 )

但是該應用正在終止。我以前見過這種行爲,但我不知道該怎麼做。 調試器控制檯這樣說:

2011-01-27 15:49:32.629 Touch[3657:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <StartUp: 0x9300f20>.' 

回答

2

由於類的UITabBarController從UIViewController類繼承,標籤欄控制器有自己的觀點,即是通過視圖屬性進行訪問。 部署標籤欄界面時,必須將此視圖安裝爲窗口的根目錄。與其他視圖控制器不同,選項卡欄界面不應該被安裝爲另一個視圖控制器的子視圖。

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITabBarController_Class/Reference/Reference.html

這是什麼意思是,這不是「允許」和蘋果可以或可能在未來拒絕你的申請。 UITabBarController旨在添加到應用程序委託中的根視圖(窗口)中。如果您希望稍後推送一個tabbar,則需要將UIToolBar與例如uisegmentedcontrol或工具欄按鈕。

即使某些應用程序做到這一點(例如WordPress的應用程序)稍後您將發現,你會在控制檯模態呈現viewcontrollers當運行到一些問題。(警告將給予)。

+0

好吧,這是否意味着我必須建立在我自己的TabBar沒有TabBarController? – teawithfruit 2011-01-27 14:54:48