我已经创建了基于导航的项目。在第二个屏幕中,我想添加uitabbarcontroller。所以任何人都可以建议我这样做。
我已经做了很多搜索,但还没有成功。所以请您提供一个简单的样本。我已经尝试过以下讨论,但我认为这不是一个好方法。
Navigation Based Application with TabBar
由于
答案 0 :(得分:2)
实际上这是正确的做法。一件不正确的事情是分配控制器的地方。这发生在之前的控制器中,正在进行推送,但应该在负责的对象中分配,TabBarController。
当您实现您的操作以显示UITabBarController时,请生成以下代码:
- (void) theAction {
SomeTabBarControllerSubClass *controller = [[SomeTabBarControllerSubClass alloc] init];
[self.navigationController pushViewController:controller animated:YES];
[controller release];
}
然后在实现SomeTabBarControllerSubClass类时:
(.h)中
@interface SomeTabBarControllerSubClass : UITabBarController {
UIViewController *first;
UIViewController *second;
}
@end
(M)
@implementation SomeTabBarControllerSubClass
- (void) viewDidLoad {
first = [[UIViewController alloc] init]; //Or initWithNib:
second = [[UIViewController alloc] init];
first.view.backgroundColor = [UIColor greenColor] //Just example
second.view.backgroundColor = [UIColor redColor] //Just example
first.tabBarItem.image = [UIImage imageNamed:@"someImage.png"];
self.viewControllers = [NSArray arrayWithObjects:first,second,nil];
}
- (void) dealloc {
[first dealloc];
[second dealloc];
[super dealloc];
}
@end