在Xcode6之后,我们可以使用一种全新的方式实现页面跳转,也就是segue,在storyboard中通过简单的连线就可以跳转页面,这大大提高了我们的开发效率,也降低了开发难度。但在有的时候,我们可能也需要使用代码来实现跳转。现在我们使用Swift代码来简单实现一下跳转。
(1)在Main.storyboard中拖入两个View Controller,在第一个界面中拖入一个按钮。并添加Action响应到代码中。
(2)为第二个界面添加Storyboard ID ,可以任意写,在等下代码中会用到。
(3)在按钮的Action响应中实现如下代码:
@IBAction func jumpTo(sender: UIButton) {
let first = self.storyboard
let secondView:UIViewController = first?.instantiateViewControllerWithIdentifier("second") as! UIViewController
self.presentViewController(secondView, animated: true, completion: nil)
}
运行以上程序,就可以实现界面跳转了。
github主页:https://github.com/chenyufeng1991 。欢迎大家访问!