通常你會創建使用的UITabBarController一個TabBar,所以在這種情況下,你可以簡單地設置屬性
@property(nonatomic, copy) NSArray *viewControllers
如果你確定你想創建中的UITabBar一樣,那麼你要使用項目屬性。類似這樣的:
- (void) setupTabBar {
UITabBar *tabBar = [[UITabBar alloc] initWithFrame:myTab];
NSMutableArray *items = [[[NSMutableArray alloc] init] autorelease];
// Add a 'test' item with no image and the text "Test"
[items addObject:[[[UITabBarItem alloc] initWithTitle:@"Test" image:nil tag:1] autorelease] ];
// Add a 'contacts' item
[items addObject:[[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:2] autorelease] ];
// Put the items in the tab bar
tabBar.items = items;
// Setup this object to respond to tab changes
tabBar.delegate = self;
}
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
if (item.tag == 2) {
// Contacts was selected. Do something...
}
}
我如何添加默認項目聯繫人? – ram
我如何設定物品的目標? – ram
我編輯了我的回覆以解決您的問題。 – Johnus