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)
mil*_*czi 115
从Xcode 7开始,您可以使用Storyboard参考以图形方式执行此操作:
将故事板参考添加到故事板.在ViewController和Storyboard Reference之间创建segue(ctrl + drag)
然后填写这些字段.
"Tutorial"是"Tutorial.storyboard"文件,"MainTutorialController"是ViewControllerSettings中的"Storyboard ID"字段
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)
但有一点需要注意的是,你已经说过要保持良好和分离.故事板的想法是让您在一个地方完成所有设计工作时保持独立.每个视图控制器都很好,并且在故事板中与其他视图控制器分开.整个想法是将它们放在一个地方.只是把它整理好,以便它有条理,你会很高兴去.除非你有充分的理由这样做,否则你不应将它分开.