uitabbarcontroller / uitabbar in navigation based project

大城市里の小女人 提交于 2019-12-19 10:46:06

问题


I have created navigation based project. and in second screen i want to add uitabbarcontroller. so can any one suggest how i do this.

i already did lot of search but no success yet. so please can you provide a simple sample of this. i already tried below discussion but i think its not a good approach.

Navigation Based Application with TabBar

Thanks


回答1:


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


来源:https://stackoverflow.com/questions/5082953/uitabbarcontroller-uitabbar-in-navigation-based-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!