i am new to iOS programming. i really need your help.
i have a login screen that takes me to a map (google API). on clicking any created annotation i want to load a tabbar with 2 views.
i searched and found out that i need to add the tabbar at the starting ie the appdelegate and show/hide the tabbar when needed.
so i made 2 functions to show and hide tabbar as
-(void)Load_tabBar{
[self.navigationController.view removeFromSuperview];
[self.window addSubview:tabBarController.view];
[self.window makeKeyWindow];}
-(void)remove_tabBar{
self.tabBarController.selectedIndex=0;
[self.tabBarController.view removeFromSuperview];
[self.window addSubview:navigationController.view];
[self.window makeKeyWindow];}
it did work when i call the Load_tabBar method and when i click back it calls remove_tabBar method. if i again call Load_tabBar method and back, it crashes giving error
-[UILayoutContainerView window]: message sent to deallocated instance 0x563b0b0
edited: PS : can i add tabbar view to a view controller and then push that view?
thnx
Answer: Use self. tabBarController?. tabBar. hidden instead of hidesBottomBarWhenPushed in each view controller to manage whether the view controller should show a tab bar or not.
The tab bar interface displays tabs at the bottom of the window for selecting between the different modes and for displaying the views for that mode. This class is generally used as-is, but may also be subclassed. Each tab of a tab bar controller interface is associated with a custom view controller.
This method definitely works. You just need to put it in the method BEFORE you push it, like this:
-actionThatPushTheViewController {
//create the view controller here, do some init.
//then:
theViewControllerToBePushed.hidesBottomBarWhenPushed = YES;
//push it here like this:
[self.navigationController pushViewController:theViewControllerToBePushed animated:YES];
use this self.hidesBottomBarWhenPushed = YES;
I hope this two methods may help you,
- (void) hideTabBar:(UITabBarController *) tabbarcontroller {
int height = 480;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
for(UIView *view in tabbarcontroller.view.subviews) {
if([view isKindOfClass:[UITabBar class]]) {
[view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];
}
else {
[view setFrame:CGRectMake(view.frame.origin.x,view.frame.origin.y, 320, 436)];
}
}
[UIView commitAnimations];
}
- (void) showTabBar:(UITabBarController *) tabbarcontroller {
int height = 480;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
for(UIView *view in tabbarcontroller.view.subviews) {
if([view isKindOfClass:[UITabBar class]]) {
[view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];
}
else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, height)];
}
}
[UIView commitAnimations];
}
Just put this two methods in AppDelegate class and call it where ever required as per you requirement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With