I have a problem creating a Tabbarcontroller at runtime in objective -c , when I call the method that creates the tabbar occurs an error:
Thread 11: EXC_BAD_ACCESS (code = 1, addess = 0x3000000c)
I think it's because I created a NavigationController as RootViewController in the AppDelegate, but I can not use tabbar as RootViewController , because I will only use this tabbar in a certain view, someone has an idea 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 {
}
}