【问题标题】:Bring Tab bar back after using navigation bar使用导航栏后带回标签栏
【发布时间】:2013-05-22 12:38:49
【问题描述】:

我有一个基于标签栏结合导航栏的应用。 在导航栏中,我有一个按钮,可以将我带到另一个我想隐藏标签栏的页面。当我试图通过一个按钮(不是返回栏按钮,常规按钮)返回主视图时,我无法将标签栏带回来。 我确实尝试过: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];

  }

谢谢! 尤西

【问题讨论】:

  • 为什么你没有为 FeedViewController 传递 nibname ??
  • 这个类没有nib文件:)

标签: iphone objective-c uinavigationbar tabbar


【解决方案1】:

这简单地解决它: [[self navigationController] popToRootViewControllerAnimated:YES];

【讨论】:

    【解决方案2】:

    FeedViewControllerviewWillAppear: 方法中,将hidesBottomBarWhenPushed 设置为NO,如下所示..

    -(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..
    

    【讨论】:

    • 谢谢,但没有帮助:(
    • 哦,好的,然后等待我会更新答案,这很简单.. :)
    • @Yossi 看到我对隐藏并显示导航栏的答案。stackoverflow.com/questions/12929951/… 尝试像隐藏标签栏的代码
    • 我想我应该在我的 appDelegete 中更改一些东西,但我不知道是什么
    • @Yossi 如果你想为 Hide 和 Show the Tabbar 做全局代码,请从这个链接查看我的答案stackoverflow.com/questions/13856184/… 创建你的 Tabbar 并使用 AppDelegate 类隐藏和显示:) 希望对你有所帮助...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-13
    相关资源
    最近更新 更多