猜到另一个故事板?

Ry-*_*Ry- 132 xcode cocoa-touch ios ios5 uistoryboard

是否可以从一个故事板转移到另一个故事板,或者将故事板嵌入到另一个故事板中的视图控制器中?我需要放置UITabBarController在一个UINavigationController,我想,让他们很好的和独立的.

lna*_*ger 200

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

// 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];
Run Code Online (Sandbox Code Playgroud)

  • 当你有多个开发人员在同一个应用程序上工作时,拥有多个故事板变得非常有用,因为在故事板xml中解决版本控制冲突有时非常痛苦. (48认同)
  • 在iOS 9和Xcode 7中,现在支持跨故事板引用.:-) (14认同)
  • 我真的想把故事板分​​开; 他们已经太杂乱了. (10认同)
  • 就像书中的章节一样,我认为需要多个故事板. (10认同)

mil*_*czi 115

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

参考

将故事板参考添加到故事板.在ViewController和Storyboard Reference之间创建segue(ctrl + drag)

然后填写这些字段.

在此输入图像描述

"Tutorial"是"Tutorial.storyboard"文件,"MainTutorialController"是ViewControllerSettings中的"Storyboard ID"字段

  • @Inafziger是的但是这个问题出现在使用iOS 9的人的搜索结果的顶部 (10认同)

wby*_*ung 10

您无法手动执行segues,因为UIStoryboardSegue是一个抽象类.您需要对其进行子类化并实现perform,以便它可以执行任何操作.它们真的意味着在故事板中创建.但是,您可以手动推送视图控制器,这是一个很好的解决方案.lnafziger的答案很好:

UIStoryboard *secondStoryBoard = [UIStoryboard storyboardWithName:@"secondStoryBoard" bundle:nil];
UIViewController *theTabBar = [secondStoryBoard instantiateViewControllerWithIdentifier:@"myTabBar"];
[self.navigationController pushViewController:theTabBar animated:YES];
Run Code Online (Sandbox Code Playgroud)

但有一点需要注意的是,你已经说过要保持良好和分离.故事板的想法是让您在一个地方完成所有设计工作时保持独立.每个视图控制器都很好,并且在故事板中与其他视图控制器分开.整个想法是将它们放在一个地方.只是把它整理好,以便它有条理,你会很高兴去.除非你有充分的理由这样做,否则你不应将它分开.

  • 合并故事板并不能很好地工作,因此在多开发人员环境中,使用单独的故事板可能会很有趣.此外,使用单个故事板的大型项目的性能也会相当糟糕. (6认同)
  • 就我而言,性能问题通常出现在Xcode中...... Apple目前对故事板编辑器的实现很薄弱. (3认同)

Dan*_*nra 7

您不应该将UITabBarControllers放在UINavigationController中.它要求出现错误,例如不正确的自动旋转/查看卸载等,因为Apple 不支持这种遏制:

但是,在组合视图控制器时,包含顺序很重要; 只有某些安排有效.从儿童到父母的遏制顺序如下:

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