2012-11-04 53 views
0

我正在使用iOS 5.1,我需要爲我的應用程序創建自定義TabBar。當應用程序啓動時,控件將被推送到Custom TabbBar控制器類。這是我正在做的。 我已經創建了派生自UITabBarController的類,並且我也使用了XIB。在XIB中,我可以看到包含Tab Bar的UIView Objetc,並且當我在該TabBar中添加更多Tab時,它不反映我何時運行App,並且只能看到一個沒有任何標題和顏色的黑色TabBar。我記得早些時候我們使用MainWindow.xib來添加TabBarController,並且爲每個TabBar項目添加導航控制器,以便每個選項卡都有自己的導航控制器,但是如果我已經使用了XIB導出,我不知道如何完成從UiTabBarController Class.Please讓我知道,如果我不清楚在任何時候。我會給予更多的澄清。我只想知道爲什麼XBB的TabBar上的更改沒有反映在應用程序中?如何使用XIB創建CustomTabBarController?

enter image description here

enter image description here

下側圖像顯示XIB和應用程序,所以你可以看到,我已經加入了四個選項卡中的UITabBar,但在應用程序中只有一個黑酒吧。

回答

0

從Apple有關UITabBarController的文檔: 此類不適用於子類。相反,您使用它的實例是爲了呈現允許用戶在不同操作模式之間進行選擇的界面。

您不能繼承它。如果原始的UITabBarController沒有你正在尋找的功能,你唯一的選擇是創建一個新的自定義標籤欄控制器,而不需要繼承原始的標籤欄控件。

編輯:不確定是否要這樣做。你只是試圖從一個筆尖加載UITabBarController?如果是這樣,則子類化不是必需的。使用故事板會更好;-)但是即使用筆尖也可以做到。 你要簡單地做到這一點:

1添加一個空的廈門國際銀行的項目,並調用它的TabBar(僅廈門國際銀行沒有源文件。)

2 - 把一個的UITabBarController該筆尖內。沒有任何其他成分,只知道的UITabBarController

3-把這個代碼在AppDelegate中應用didFinishLaunchingWithOptions方法:

// this code should be already in that method if you have used the empty application model 
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

// this is the new code to add. You are programmatically loading an instance of UITabBarController from the nib named TabBar.xib 
UITabBarController *tb = (UITabBarController *)[[[NSBundle mainBundle]loadNibNamed:@"TabBar" owner:self options:nil] objectAtIndex:0]; 
// here you are assigning the tb as the root viewcontroller 
self.window.rootViewController = tb; 

// this code is standard in this method 
// Override point for customization after application launch. 
self.window.backgroundColor = [UIColor whiteColor]; 
[self.window makeKeyAndVisible]; 
return YES; 

然後你可以定製你的UITabBarController,它應該正確加載。 小心:如果添加筆尖內的其他對象,你必須更改線路

與環路和一些檢查,看看是否你真的加載的UITabBarController,而不是其他組件。現在我只是簡單地將第一個對象加載到筆尖中,而不用擔心它是UITabBarController還是UIPotato ;-)

+0

您是說我無法創建從UITabBarController派生的類? – Developer

+0

不確定你的意思是「派生」。 「你不能繼承子類」的意思是你不能創建這樣的類:'@interface MyTabBarController:UITabBarController' – LombaX

+0

不,我們可以做到這一點,而且之前我做了很多次,但是我從來沒有使用過XIB for這個目的! – Developer

相關問題