[英]How to move to an existing UIViewController (in storyboard) with code in swift
I know how to do it with buttons by clicking and dragging, but I have a situation where I need a transition without a button. 我知道如何通过单击和拖动来使用按钮来完成此操作,但是我遇到一种情况,我需要没有按钮的过渡。 so what code will allow me to transition from the current UIViewController to a different UIViewController that is already initialized?
那么什么代码将允许我从当前的UIViewController过渡到已经初始化的另一个UIViewController?
First, you will need to create the segue in the storyboard and give a proper name to the identifier of this segue. 首先,您需要在情节提要中创建序列,并为该序列的标识符指定适当的名称。 You can do this by clicking on the segue (left panel) and then click on Attributes (right panel).
您可以通过单击segue(左侧面板),然后单击Attributes(右侧面板)来执行此操作。
The same way you can call this segue using buttons or selection of table rows from your storyboard, you can call it from code using performSegueWithIdentifier:sender:
使用按钮或从情节提要中选择表行来调用此segue的方式相同,也可以使用
performSegueWithIdentifier:sender:
从代码中调用它performSegueWithIdentifier:sender:
As when using the button and cells on uitableview, your view controller call prepareForSegue:
You override this method in your view if you need to pass any data between controllers: 与在uitableview上使用按钮和单元格一样,视图控制器调用
prepareForSegue:
如果需要在控制器之间传递任何数据,则可以在视图中覆盖此方法:
override func prepareForSegue(segue: UIStoryboardSegue?, sender: AnyObject?) {
if segue!.identifier == "MySegue" {
let viewController:ViewController = segue!.destinationViewController as ViewController
viewController.receiveSomedata = self.sendSomeData
}
}
When you want to go to next viewController 当您想转到下一个viewController时
self.performSegueWithIdentifier("yoursegue", sender: nil)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.