【问题标题】:How do you go from one storyboard to another? not view to view within a storyboard你如何从一个故事板转到另一个故事板?不在情节提要中查看
【发布时间】:2012-12-03 04:21:33
【问题描述】:

您好,我创建了两个故事板文件,但我不知道如何在它们之间切换。为了在一个故事板中切换,我设置了标识符并使​​用以下代码:

[self performSegueWithIdentifier:@"identifier" sender:self];

此代码在用于切换情节提要时使应用程序崩溃。

请帮忙

【问题讨论】:

    标签: iphone objective-c ios xcode storyboard


    【解决方案1】:

    iOS 9.0 的更新答案

    您可以使用情节提要中的情节提要引用将转场的目的地设置为另一个情节提要中的视图控制器。将故事板引用从对象库拖到源故事板。使用目标故事板的名称和该故事板中目标视图控制器的标识符对其进行配置。然后,您可以将引用用作源故事板中转场的目的地。

    更多详情请见“Adding a Reference to Another Storyboard” in Storyboard Help

    原答案

    看看UIStoryboard Class Reference

    您可以使用+[UIStoryboard storyboardWithName:bundle:] 按名称加载情节提要。拥有故事板对象后,您可以通过发送instantiateInitialViewControllerinstantiateViewControllerWithIdentifier: 来实例化其中一个视图控制器。然后你可以用那个视图控制器做任何你想做的事情:以模态方式呈现它,将它推送到导航控制器上,将它添加到标签栏控制器等等。

    您无法在不同故事板中的场景之间创建转场,因此您无法使用 performSegueWithIdentifier:sender: 从一个故事板中的场景过渡到另一个故事板中的场景。

    【讨论】:

      【解决方案2】:

      我找到了自己问题的答案!

      这是我的问题的代码:

      -(void)viewDidLoad {
      
          if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
              CGSize result = [[UIScreen mainScreen] bounds].size;
      
              if(result.height == 480){}
              if(result.height == 568){[self performSelector:@selector(inch4) withObject:nil afterDelay:0];}}}
      
      
      
      -(void)inch4 {
      
          UIStoryboard *storyBoard;
      
          storyBoard = [UIStoryboard storyboardWithName:@"iPhone4inch" bundle:nil];
          UINavigationController *init4inchViewController = [storyBoard instantiateViewControllerWithIdentifier:@"MainMenu4inch"];
          [self presentModalViewController:init4inchViewController animated:NO];
      
      }
      

      这里是切换故事板文件的代码:

      UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"storyboard2" bundle:nil];
      [self presentModalViewController:[storyboard instantiateViewControllerWithIdentifier:@"storyboard2initialviewcontroller"] animated:NO];
      

      【讨论】:

      • 您可能应该接受这些答案中的一个。两者相同且正确。
      • 它说我明天试试就可以了
      • 要将标识符添加到您的故事板,请关注this link
      【解决方案3】:

      在swift中,这很简单,如下所示。 :)

          let sb = UIStoryboard(name: "DestinationStoryboard", bundle: nil)
          let vc = sb.instantiateInitialViewController() {
             present(vc, animated: true, completion: nil)
          }
      

      【讨论】:

      • 伙计,你无法相信我一直在寻找这个答案。谢谢!
      猜你喜欢
      • 2013-09-17
      • 2017-02-22
      • 2014-11-13
      • 2012-03-23
      • 1970-01-01
      • 2017-01-04
      • 1970-01-01
      • 2017-05-14
      • 2016-04-07
      相关资源
      最近更新 更多