【问题标题】:How to fix Segue from ViewController to a Storyboard Tabbar Controller Programmatically does not show Tabbar Menu?如何以编程方式将 Segue 从 ViewController 修复到 Storyboard Tabbar Controller 不显示 Tabbar 菜单?
【发布时间】:2014-07-27 13:42:07
【问题描述】:

我目前看到,当我转到另一个 StoryBoard ViewController 时,它是 Tabbar 菜单的一部分。它显示了 ViewController 但不显示菜单标签栏。

这是我的代码

- (IBAction)endCall:(id)sender {

    NSLog(@"End Call");

    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"callHistory"];
    [self presentViewController:vc animated:YES completion:nil];

}

注意:用户最近历史视图控制器仅包含一个 ViewController .m 并链接到 Storyboard 上的 Storyboard Tabbar Controller 它不包含 TabbarController 类

【问题讨论】:

  • 你必须在它们之间嵌入一个导航控制器。

标签: objective-c uiviewcontroller uitabbarcontroller


【解决方案1】:

我建议您为标签栏使用 UITabBarController 并转而使用标签栏视图控制器。然后在您的 tabBarViewController viewdidload() 方法中,您可以选择要显示的选项卡。

我个人会像这样在 tabBarViewController.h 中声明一个名为“backFromStart”的 BOOL 属性->

@property (nonatomic, assign) BOOL backFromStart;

然后在 startCellViewController 的 prepareForSegue:() 方法中设置这个 BOOL,如下所示:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
  if ([[segue identifier] isEqualToString:@"backToTabBarVC"])
    {
       TabBarVC *destinationVC = segue.destinationViewController;
       destinationVC.backFromStart = YES;
       // Pass any other data to the callHistoryVC if required like so->
       callHistoryVC *historyVC = [destinationVC.viewControllers objectAtIndex:0]; // objectAtIndex 0 as this is your first and only tab.

    }
}

如果在 tabBarController.m viewdidload() 方法中设置了 BOOL "backFromStart",则最后选择选项卡:

if(backFromStart) {
  backFromStart = NO;
  [self setSelectedIndex:0];
}

注意:现在由于您只有一个选项卡,因此实际上并不需要 BOOL,但以防万一您决定添加更多选项卡!

【讨论】:

  • 如何使用这个在 IBAction endCall 上手动执行 segue??
  • [self performSegueWithIdentifier: @"backToTabBarVC" sender: self];在 IBAction 上可以吗?
  • 您可以从按钮本身的界面构建器创建一个名为“back ToTabBarVC”的模态segue。
猜你喜欢
  • 2017-07-13
  • 2014-11-06
  • 2023-03-24
  • 1970-01-01
  • 1970-01-01
  • 2019-07-02
  • 1970-01-01
  • 1970-01-01
  • 2012-02-26
相关资源
最近更新 更多