2
在iOS中,TabBarController中的TabBar屬性是隻讀的。我如何將自定義項目與特定的視圖控制器相關聯?如何訪問tabBar內的UITabBarItems?以編程方式設置自定義UITabBarItem?
像這樣
CustomView *custom = [[CustomView alloc] init];
UITabBarItem *customTab = [[UITabBarItem alloc] initWithTitle:@"Custom" image:[UIImage imageNamed:@"custom.png"] tag:0];
SecondView *second = [[SecondView alloc] init];
UITabBarItem *secondTab = [[UITabBarItem alloc] initWithTitle:@"Next" image:[UIImage imageNamed:@"next.png"] tag:1];
NSArray *views = [NSArray arrayWithObjects:custom,second,nil];
[tabBarController setViewControllers:views];
//how do I set the individual TabBarItems (customTab,secondTab) to be associated
//with the views in question? tabBarController.tabBar is read only
嘗試使用tabBar修改tabBar:setItems:animated是一個禁忌。 ***終止應用程序,由於未捕獲異常'NSInternalInconsistencyException',原因:'不允許直接修改由標籤欄控制器管理的標籤欄。 – Justin 2010-10-11 16:11:15