I’ve spent ages stuck on this: Using the Tab Bar template (without storyboard) I can easily switch between tabs and switch between views within each table, however when it comes to swapping between a UITabBarController and a UIViewController whatever code i keep trying won’t work.
-(IBAction)tabtoview:(id)sender{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp
forView:self.view
cache:YES];
[self.tabBarController removeFromParentViewController];
[self.view addSubview:self.mainscreen]; //Crashes here
[UIView commitAnimations];
}
Rather than removing the tabBarController it would be preferable if I could hide/disable it after having animated. Any help is appreciated thanks!
I think you problem is that
UITabBarControllerandUINavigationControllerare those kind of controllers that cannot be handled the way you are doing.You’d better subclass your
UIWindowinapp delegateand move the-(IBAction)tabtoview:(id)sender;method into the subclass ofUIWindow. I tried and it works.The reason is, you must have a controller to take the responsibility of switching views. What you are trying to do is, swapping controllers, rather than views. And that’s a conflict. Tabs are part of
UITabController, they are not views! It is also the same story forUINavigationController.So, if you are simply swapping views, you can do it right in one of your viewControllers, but swpaping a controller with another (i.e.
UIViewcontrollerwithUITabBarController) should be handled in a higher level, i.e. app delegate. The only instance available in that level is yourUIWindow.