2012-02-06 69 views
5

我是iOS編程新手。我真的需要你的幫助。從視圖控制器需要時顯示/隱藏tabbar

我有一個登錄屏幕,帶我到地圖(谷歌API)。點擊任何創建的註釋我想加載2個視圖的標籤欄。

我搜索了一下,發現我需要在開始處添加tabbar,即appdelegate,並在需要時顯示/隱藏tabbar。

所以我做了2個功能,以顯示和隱藏的TabBar作爲

-(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];} 

它的工作時,我稱之爲Load_tabBar方法,當我點擊返回調用remove_tabBar方法。如果我再次調用Load_tabBar方法和背部,它崩潰給錯誤

- [UILayoutContainerView窗口]:消息發送到釋放的實例0x563b0b0

編輯:PS:我可以添加的TabBar視圖的視圖控制器,然後推送視圖?

日Thnx

回答

8

使用本self.hidesBottomBarWhenPushed = YES;

+0

添加BT還是一樣:( – 2012-02-06 11:51:38

+0

我可以添加的TabBar視圖視圖控制器,然後按該視圖 – 2012-02-06 11:52:22

+0

當你是誰?推視圖控制器在該呈現視圖控制器中,你必須在viewWillAppear方法中添加此視圖。無需使用您的代碼 – Tendulkar 2012-02-06 11:53:15

1

我希望這兩個方法可以幫助你,

- (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]; 

}

只需將這兩個方法放在AppDelegate類中,並根據需要隨時調用它。

+0

我不想更改子視圖的幀大小..當彈出時,它會彈出另一個視圖.. subviews也不見了 – 2012-02-06 13:52:07

+0

然後只是設置大小,你需要!!!! – 2012-02-06 13:55:35

+0

似乎工作得很好,我添加了一些調整來處理iPhone和iPad。獲取窗口的寬度和高度,如下所示 float height = self.window.frame.size.height; float width = self.window.frame.size.width; – Sheepdogsheep 2012-08-27 15:59:58

1

這種方法絕對有效。你只需把它的方法之前,你推它,就像這樣:

-actionThatPushTheViewController { 

    //create the view controller here, do some init. 

    //then: 
    theViewControllerToBePushed.hidesBottomBarWhenPushed = YES; 

    //push it here like this: 
    [self.navigationController pushViewController:theViewControllerToBePushed animated:YES]; 
相關問題