我有一個UITabBarController管理5個視圖控制器。我在他們的「init」方法中創建它們的標籤欄項目,以便它們將在視圖加載之前顯示。我只是想知道我該怎麼做,因爲似乎有很多方法。例如,對於我的DatePickerViewController:iPhone開發 - UIViewController標題,tabBarItem,標籤
- (id)init {
if((self = [super init])) {
// ================ THIS ==========================
UIImage *clockIcon = [UIImage imageNamed:@"clockicon.png"];
UITabBarItem *localTabBarItem = [[UITabBarItem alloc]
initWithTitle:@"Date" image:clockIcon tag:0];
[self setTabBarItem:localTabBarItem];
[localTabBarItem release];
// ================ OR THIS ========================
[self setTitle:@"Date"];
UITabBarItem *localTabBarItem = [[UITabBarItem alloc] init];
[localTabBarItem setImage:[UIImage imageNamed:@"clockicon.png"]];
[self setTabBarItem:localTabBarItem];
[localTabBarItem release];
// ================ OR THIS ========================
UITabBarItem *localTabBarItem = [[UITabBarItem alloc] init];
[localTabBarItem setTitle:@"Date"];
[localTabBarItem setImage:[UIImage imageNamed:@"clockicon.png"]];
[self setTabBarItem:localTabBarItem];
[localTabBarItem release];
}
return self;
}
我應該怎樣做?爲什麼tabBarItem和View Controller都有標題?我不認爲我需要標籤(在第一種方法中設置)。
謝謝!
只是好奇,是否有一個原因,你不在IB設置? – 2009-08-20 20:59:32
我不使用IB。 – mk12 2009-08-20 21:17:50
我想那時你可能會走出困境。 – 2009-08-20 22:38:24