xcode 您如何从一个故事板转到另一个故事板?不查看以在故事板中查看

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13890997/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 02:20:08  来源:igfitidea点击:

How do you go from one storyboard to another? not view to view within a storyboard

iphoneobjective-ciosxcodestoryboard

提问by OnkaPlonka

Hi I have created two storyboard files and I have no Idea how I would switch between them. For switching within one storyboard I set the Identifier and use this code:

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

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

this code crashes the app when it is used to switch storyboards.

当使用此代码切换故事板时,此代码会使应用程序崩溃。

Please help

请帮忙

回答by rob mayoff

Updated Answer for iOS 9.0

iOS 9.0 的更新答案

You can use a storyboard reference in a storyboard to set the destination of a segue to a view controller in another storyboard. Drag a storyboard reference from the Object library to your source storyboard. Configure it with the name of the destination storyboard and the identifier of the destination view controller in that storyboard. Then you can use the reference as the destination for segues in the source storyboard.

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

See “Adding a Reference to Another Storyboard” in Storyboard Helpfor more details.

有关更多详细信息,请参阅Storyboard 帮助中的“添加对另一个 Storyboard 的引用”

Original Answer

原答案

Take a look at the UIStoryboard Class Reference.

看看UIStoryboard 类参考

You can load a storyboard by name using +[UIStoryboard storyboardWithName:bundle:]. Once you have the storyboard object, you can instantiate one of its view controllers by sending it instantiateInitialViewControlleror instantiateViewControllerWithIdentifier:. Then you can do whatever you want with that view controller: present it modally, push it on a navigation controller, add it to a tab bar controller, etc.

您可以使用+[UIStoryboard storyboardWithName:bundle:]. 一旦你有了 storyboard 对象,你就可以通过发送它instantiateInitialViewControllerinstantiateViewControllerWithIdentifier:. 然后你可以用那个视图控制器做任何你想做的事情:以模态呈现它,将它推送到导航控制器上,将它添加到标签栏控制器,等等。

You cannot create a segue between scenes in different storyboards, so you cannot use performSegueWithIdentifier:sender:to transition from a scene in one storyboard to a scene in another storyboard.

您不能在不同情节提要中的场景之间创建转场,因此您不能使用performSegueWithIdentifier:sender:从一个情节提要中的场景过渡到另一个情节提要中的场景。

回答by OnkaPlonka

I've found the answer to my own question!

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

Here's the code for my problem:

这是我的问题的代码:

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

}

here's the code to switch storyboard files:

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

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

回答by Anfaje

In swift, this is as simple as below. :)

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

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