使用导航栏后返回标签栏

时间:2013-05-22 12:38:50

标签: iphone objective-c uinavigationbar tabbar

我有一个基于Tab Bar和导航栏的应用程序。 在导航栏中,我有一个按钮,将我带到另一个页面,我想隐藏标签栏。当我试图通过按钮(不是后退栏按钮,常规按钮)回到主视图时,我无法将Tab栏带回来。 我确实尝试过:xxxxx.hidesBottomBarWhenPushed =NO;

以下是我的一些代码:

在主视图中:

viewDidLoad:

 UIBarButtonItem *flipButton = [[UIBarButtonItem alloc]
                               initWithTitle:buttonTitle
                               style:UIBarButtonItemStylePlain
                               target:self
                               action:@selector(goToCreateEvent)]; 




-(void)goToCreateEvent{
     UIViewController *targetViewController;
     NSString *viewControllerName = @"CreateAnEventViewController";
     targetViewController = [[NSClassFromString(viewControllerName) alloc]   initWithNibName:viewControllerName bundle:nil];
     targetViewController.hidesBottomBarWhenPushed =YES; //Hides the tab bar
     [self.navigationController pushViewController:targetViewController animated:YES];

 }

在另一个视图中:

-(IBAction)save:(id)sender
 {
    [summary resignFirstResponder];
    [agenda resignFirstResponder];

    FeedViewController *aboutViewCont = [[FeedViewController alloc] init];

    aboutViewCont.hidesBottomBarWhenPushed =NO; //trying to bring back the tab bar

    [[self navigationController] pushViewController:aboutViewCont animated:NO];

  }

谢谢! 贝纳

2 个答案:

答案 0 :(得分:1)

这只是解决它:  [[self navigationController] popToRootViewControllerAnimated:YES];

答案 1 :(得分:0)

viewWillAppear: FeedViewController方法hidesBottomBarWhenPushedNO设置为-(void)viewWillAppear:(BOOL)animated{ self.hidesBottomBarWhenPushed = NO; } ,如下所述..

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

    CGRect r = self.tabBarController.view.frame;
    r.size.height +=self.tabBarController.tabbar.frame.size.height;
    self.tabBarController.view.frame = r;
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.tabBarController.view.frame = CGRectMake(0, 0, 320, 480); //for iPhone portrait
}

更新:试试这个......

FeedViewController

targetViewController.hidesBottomBarWhenPushed =YES;//comment this.. 课程中使用上述方法,并且只需在代码中对此下划线进行评论..

{{1}}