【发布时间】:2011-07-29 02:35:23
【问题描述】:
我有一个 UIViewController,我希望像下面的屏幕截图那样放置一个简单的 UITabBar:我不想使用 UITabBarController。事实上,我最初的设置使用了一个,而且很容易让它工作。
但是,我发现将 UITabBarControllers 放在导航控制器中是个坏主意,所以我不得不重构层次结构(所以请不要建议使用)。
给定一个 UIViewController,如何以编程方式在底部添加一个 UITabBar?我得到了我的 UITabBarDelegate 所有设置,以在单击其中一个选项卡栏时显示特定视图,但问题是当视图控制器加载时,没有显示选项卡栏!这是我的代码:
- (void) viewDidLoad {
...some initialization...
CGRect frame = CGRectMake(0, 431, 320, 49);
profileItem = [[UITabBarItem alloc] init];
profileItem.image = icon;
profileItem.title = @"Diet";
tabBar = [[UITabBar alloc] initWithFrame:frame];
NSArray* items = [[NSArray alloc] initWithObjects:profileItem, nil];
tabBar.items = items;
tabBar.delegate = self;
[tabBar setSelectedItem:[tabBar.items objectAtIndex:0]];
[self.view addSubview:tabBar];
[super viewDidLoad];
}
我在这里错过了什么?
编辑:啊,我发现它与框架有关......嗯......如果我在顶部有一个现有的导航标题,我应该使用什么 y 坐标?
【问题讨论】:
标签: iphone objective-c