uitabbarcontroller / uitabbar in navigation based project

牧云@^-^@ 提交于 2019-12-01 12:49:49

Actually this is the correct approach. The one thing that is not correct is where the controllers are allocated. This is happened in the previous controller, the one that is making the push, but should be allocated in the object that is responsible, the TabBarController.

When you implement your action to show the UITabBarController make the following code:

- (void) theAction {
   SomeTabBarControllerSubClass *controller = [[SomeTabBarControllerSubClass alloc] init];
   [self.navigationController pushViewController:controller animated:YES];
   [controller release];
}

Then when you implement the SomeTabBarControllerSubClass class:
(.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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!