0
I’m having a problem creating a Tabbarcontroller at runtime in objective-c, when I call the method that creates the tabbar an error occurs:
Thread 11: EXC_BAD_ACCESS(code=1, addess=0x3000000c)
I believe it’s because I created a Navigationcontroller as Rootviewcontroller no Appdelegate, but I can not use the tabbar as Rootviewcontroller, because I will only use this tabbar in a given view, someone has an idea of how to do this without this type of error, follow the code.
-(void)criarTab{
MenuOpcao *vc1 = [[MenuOpcao alloc] initWithNibName:@"MenuOpcao" bundle:[NSBundle mainBundle]];
Carrinho *vc2 = [[Carrinho alloc] initWithNibName:@"Carrinho" bundle:[NSBundle mainBundle]];
NSMutableArray *topLevelControllers = [[NSMutableArray alloc] init];
[topLevelControllers addObject: vc1];
[topLevelControllers addObject: vc2];
vc1.title = @"Carrinho";
vc2.title = @"Tipos de Pratos";
vc1.tabBarItem.image = [UIImage imageNamed:@"filtro@2x"];
vc2.tabBarItem.image = [UIImage imageNamed:@"carrinho@2x"];
NSString *valorBagde =[[NSString alloc] initWithFormat:@"%lu", (long)ContaCarrinho ];
vc2.tabBarItem.badgeValue=valorBagde;
tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate = self;
@try {
[tabBarController setViewControllers:topLevelControllers animated:YES];
tabBarController.selectedIndex = 0;
tabBarController.view.bounds = [[UIScreen mainScreen] bounds];
tabBarController.view.frame = [[UIScreen mainScreen] bounds];
tabBarController.view.frame = CGRectMake(0,0,self.view.frame.size.width,h);
[self.view addSubview:tabBarController.view];
Tabok=2;
[self.tabBarController.tabBar setBackgroundColor:[UIColor colorWithHexString:@"#ed2a69"]];
}
@catch (NSException *exception) {
NSLog(@"%@", exception.reason);
NSLog(@"%@", exception.description);
}
@finally {
}
}
Thanks for the tip, this problem I already managed to solve, now I have another problem, now when pressing an item of tabbar the navigationbar is not displayed you would know how I can solve this?
– Bruno Richart
For every item of your
UITabView, you have to add oneUINavigationView. If in this case, you want the navigation bar to be shared between all tabs, then you will have to customize a Uitabview from a Uiviewcontroller, Apple does not recommend that a Uinavigationcontroller push an Uitabbarcontroller inside itself.– Jan Cássio
It was clear, but in case I use a tabbar content two controls and also use a navigationbar, navigation only has buttons but I use the tab to navigate between the screens.
– Bruno Richart