第一次海報。提前致謝。爲什麼不顯示UITabBarItems的標題?
我想在我的iPhone應用程序中使用UITabBar。我被引導認爲我不能使用UITabViewController,因爲我將它嵌套在UINavigationController中。我讀過你可以做到這一點,但你必須使用UITabBar而不是完整的控制器。我可以使用Interface Builder進行這項工作,但是我有很多冗餘的XIB,我寧願在代碼中使用它。我想知道魔法是如何運作的。
這裏是我的控制器的.m:
#import "DumbViewController.h"
@implementation DumbViewController
-(void) loadView {
UIView *view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, 150, 30)];
[label setText:@"hello world"];
[view addSubview:label];
[label release];
UITabBar *tb = [[UITabBar alloc] initWithFrame:CGRectMake(0, [view frame].size.height - 64, [view frame].size.width, 64)];
[tb setDelegate:self];
[tb setItems:[NSArray arrayWithObject:[[[UITabBarItem alloc] initWithTitle:@"bob" image:[UIImage imageNamed:@"21-skull.png"] tag:0] autorelease]]];
[view addSubview:tb];
[tb release];
[self setView:view];
[view release];
}
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
NSLog(@"selected item %@", item);
}
@end
當我運行應用程序,讓我的標籤,並在底部的標籤欄。我得到了愚蠢的小頭骨圖標,但「鮑勃」從不顯示。按照你所期望的那樣點擊頭骨。
爲什麼不顯示該標題?
謝謝!
這產生了與我原來的代碼相同的結果。無題。 – bmauter
我建議你去用UIButtons而不是TabbarItems。 –
爲什麼?我的標籤欄只是在屏幕外。現在它在屏幕上,它完美的工作。 UIButton有什麼優勢? – bmauter