是否可以从一个故事板分割到另一个故事板,或者将一个故事板嵌入到另一个故事板的视图控制器中?我需要在UINavigationController
中放置一个UITabBarController
,并且我想让它们保持良好和分离。
发布于 2012-03-08 07:50:54
是的,但是你必须以编程的方式来完成:
// 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];
发布于 2015-11-17 17:21:20
从Xcode 7开始,您可以使用Storyboard引用以图形方式完成此操作:
将情节提要引用添加到情节提要。在ViewController和故事板引用之间创建分段(按住Ctrl键并拖动)
然后填写这些字段。
其中"Tutorial“是"Tutorial.storyboard”文件,"MainTutorialController“是ViewControllerSettings中的"Storyboard ID”字段
发布于 2012-03-12 06:31:47
你不能手动处理segues,因为UIStoryboardSegue是一个抽象类。您需要将其子类化并实现perform
,这样它才能执行任何操作。它们实际上是在故事板中创建的。不过,您可以手动推送视图控制器,这是一个很好的解决方案。lnafziger的答案做得很好:
UIStoryboard *secondStoryBoard = [UIStoryboard storyboardWithName:@"secondStoryBoard" bundle:nil];
UIViewController *theTabBar = [secondStoryBoard instantiateViewControllerWithIdentifier:@"myTabBar"];
[self.navigationController pushViewController:theTabBar animated:YES];
不过,有一件事需要注意,你说过你想让事情保持良好和独立。故事板的想法是让你在一个地方做所有的设计工作的同时,保持事物的分离。每个视图控制器都很好,并且在故事板中与其他控制器分开。整个想法就是把所有的东西都放在一个地方。只要把它布置好,这样它就有条理了,你就可以行动了。除非你有一个非常好的理由,否则你不应该把它分开。
https://stackoverflow.com/questions/9575702
复制相似问题