[英]How to Programmatically Segue to a New ViewController in a New Storyboard
I simply want to know how to segue to a new view controller in a new storyboard without having to create the new view controller programmatically. 我只是想知道如何在新的情节提要中选择到新的视图控制器,而不必以编程方式创建新的视图控制器。
The Scenario: I have one view controller that's created entirely in code and the system thinks I'm in Storyboard A. I want to segue from this view controller to another view controller that's contained on Storyboard B. 场景:我有一个完全用代码创建的视图控制器,系统认为我在情节提要A中。我想从此视图控制器中选择到情节提要B中包含的另一个视图控制器。
If there are other options I'm not aware of please include them below! 如果还有其他我不知道的选项,请在下面列出!
This piece of code allows you to segue to any viewController anywhere in your application while still being able to build your viewController with storyboard. 这段代码使您可以在应用程序中的任何位置选择任何viewController,同时仍然能够使用情节提要构建您的viewController。
func settingsButtonPressed(sender:UIButton) {
let storyboard = UIStoryboard(name: "AccountLinking", bundle: nil)
let linkingVC = storyboard.instantiateViewControllerWithIdentifier("AccountLinkingTable")
self.navigationController?.pushViewController(linkingVC, animated: true)
}
So many hours saved thanks to this little function. 这个小功能节省了很多小时。
我敦促所有阅读此文章的人阅读Xcode 7中引入的Storyboard Reference ,以实现此目的,而不是通过编程方式加载Storyboard。
You can override the below function to override the segue call. 您可以覆盖以下功能以覆盖segue调用。
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var destinationController = segue.destinationViewController
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.