ios 转到另一个故事板?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9575702/
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-08-30 17:10:46  来源:igfitidea点击:

Segue to another storyboard?

iosxcodecocoa-touchios5uistoryboard

提问by Ry-

Is it possible to segue from one storyboard to another, or to embed a storyboard in a view controller in another storyboard? I need to place a UITabBarControllerin a UINavigationController, and I'd like to keep them nice and separate.

是否可以从一个情节提要到另一个情节提要,或者在另一个情节提要中的视图控制器中嵌入一个情节提要?我需要将 aUITabBarController放在 a 中UINavigationController,我想让它们保持良好和独立。

回答by lnafziger

Yes, but you have to do it programmatically:

是的,但您必须以编程方式执行此操作:

// Get the storyboard named secondStoryBoard from the main bundle:
UIStoryboard *secondStoryBoard = [UIStoryboard storyboardWithName:@"secondStoryBoard" bundle:nil];

// Load the initial view controller from the storyboard.
// Set this by selecting 'Is Initial View Controller' on the appropriate view controller in the storyboard.
UIViewController *theInitialViewController = [secondStoryBoard instantiateInitialViewController];
//
// **OR**  
//
// Load the view controller with the identifier string myTabBar
// Change UIViewController to the appropriate class
UIViewController *theTabBar = (UIViewController *)[secondStoryBoard instantiateViewControllerWithIdentifier:@"myTabBar"];

// Then push the new view controller in the usual way:
[self.navigationController pushViewController:theTabBar animated:YES];

回答by milczi

From Xcode 7 onwards, you can do this graphically by using a Storyboard Reference:

从 Xcode 7 开始,您可以使用 Storyboard Reference 以图形方式执行此操作:

reference

参考

Add Storyboard Reference to your storyboard. Create segue between ViewController and Storyboard Reference (ctrl + drag)

将故事板参考添加到您的故事板。创建的ViewController和故事板之间参考赛格瑞(CTRL +拖动)

Then fill this fields.

然后填写此字段。

enter image description here

在此处输入图片说明

Where "Tutorial" is "Tutorial.storyboard" file and "MainTutorialController" is your "Storyboard ID" field in ViewControllerSettings

其中“Tutorial”是“Tutorial.storyboard”文件,“MainTutorialController”是您在 ViewControllerSettings 中的“Storyboard ID”字段

回答by wbyoung

You can't really do segues manually because UIStoryboardSegue is an abstract class. You need to subclass it and implement performin order for it to do anything. They're really meant to be created in storyboards. You can push the view controller manually, though, which is a good solution. lnafziger's answer does this well:

您不能真正手动执行 segue,因为 UIStoryboardSegue 是一个抽象类。您需要对它进行子类化并实现perform它才能执行任何操作。它们真的是要在故事板中创建的。不过,您可以手动推送视图控制器,这是一个很好的解决方案。lnafziger 的回答做得很好:

UIStoryboard *secondStoryBoard = [UIStoryboard storyboardWithName:@"secondStoryBoard" bundle:nil];
UIViewController *theTabBar = [secondStoryBoard instantiateViewControllerWithIdentifier:@"myTabBar"];
[self.navigationController pushViewController:theTabBar animated:YES];

One thing to note, though, is that you've said you want to keep things nice and separate. The idea of storyboards is to allow you to keep things separate while doing all of your design work in one place. Each view controller is nice and separated within the storyboard from the others. The whole idea is to keep it all in one place. Just lay it out nicely so that it's organized, and you'll be good to go. You shouldn't separate it unless you have a really good reason to do so.

不过,要注意的一件事是,您已经说过要让事情保持良好和独立。故事板的想法是让您在一个地方完成所有设计工作的同时将事物分开。每个视图控制器都很好,并且在故事板中与其他视图控制器分开。整个想法是将所有内容都放在一个地方。只需将其布置得井井有条,您就可以开始了。你不应该分开它,除非你有很好的理由这样做。

回答by Danra

You should not place UITabBarControllers in a UINavigationController. It's asking for bugs such as incorrect autorotation/view unloading etc., as Apple doesn't supportthis sort of containment:

你不应该把 UITabBarControllers 放在 UINavigationController 中。它要求提供错误,例如不正确的自动旋转/视图卸载等,因为 Apple不支持此类遏制:

When combining view controllers, however, the order of containment is important; only certain arrangements are valid. The order of containment, from child to parent, is as follows:

  • Content view controllers, and container view controllers that have flexible bounds (such as the page view controller)
  • Navigation view controller
  • Tab bar controller
  • Split view controller

然而,在组合视图控制器时,包含的顺序很重要;只有某些安排是有效的。从孩子到父母的收容顺序如下:

  • 内容视图控制器和具有灵活边界的容器视图控制器(例如页面视图控制器)
  • 导航视图控制器
  • 标签栏控制器
  • 拆分视图控制器

回答by DudeOnRock

Here is a swift version:

这是一个快速版本:

let targetStoryboardName = "Main"
let targetStoryboard = UIStoryboard(name: targetStoryboardName, bundle: nil)
if let targetViewController = targetStoryboard.instantiateInitialViewController() {
    self.navigationController?.pushViewController(targetViewController, animated: true)
}

回答by moxy

did you try the following :

您是否尝试过以下操作:

2/ click to select your view controller which is linked to your navigation controller and in top menu : editor -> embed in -> Tab Bar controller

2/ 单击以选择链接到导航控制器和顶部菜单的视图控制器:编辑器 -> 嵌入 -> 标签栏控制器

Note : I didn't test it because I'm using the opposite : making tabbed bar apps and puting navigation controller inside).

注意:我没有测试它,因为我正在使用相反的方法:制作标签栏应用程序并将导航控制器放入其中)。