Swift 页面跳转
swift2.x,xcode7.1 有人会问现在swift4.0都粗来了,为啥还用swift2.x? 原因是:之前的项目使用的是Swift2.X编写的。如过升级xcode 使用swift3.0或者swift4.0,程序修改量很大。而且像我这种初级水平并没有把握保证程序的质量。保守起见还是先不升级xcode 暂时还是使用swit2.x编写吧。最重要的是公司没有预留时间修改。 关于页面跳转,网上有很多博客。但是你会发现好多不能用?其实是没有讲解清楚。 关于页面跳转有两种方式: 需要注意的是这两种方式的使用场景是不一样的! 区别是:一种是使用代码手写界面,另一种是使用Storyboard 第一种(手写界面)
var
vc
=
MyViewController
()
self
.
presentViewController
(
,
animated
:
true
completion
nil
)
第二种(storyboard制作的界面) storyboard制作的界面跳转方式又分为两种 1、通过在storyboard中拉button控件建立segue跳转,连线跳转(这种比较简单我就不讲解了) 2、通过代码进行界面跳转。 (1)使用presentViewController跳转 var sb = UIStoryboard(name: "Main",bundle:nil)
var vc = sb.instantiateViewControllerWithIdentifier("VC") as ViewController
//VC为该界面storyboardID,Main.storyboard中选中该界面View,Identifier inspector中修改
self.presentViewController(vc,animated: true,completion: nil)
关闭当前界面: //前提:通过 View的presentViewController跳转的页面才能执行,否则找不到上一页 //同样可以执行关闭此页时的闭包操作 self.dismissViewControllerAnimated(true,completion: nil) (2)使用pushViewController跳转
如果父控件在NavigationController中也可以使用下面的方式跳转: self.navigationController?.pushViewController(vc,animated: true) 使用这种方式跳转关闭的时候也是有固定方式的例如:返回到根视图 self.navigationController?.popToRootViewControllerAnimated(true)
参考: http://www.jianshu.com/p/f69e8a5ae4f9 http://www.cnblogs.com/amourjun/p/amourjun.html http://www.jianshu.com/p/bad9b3823260 http://www.woowen.com/swift/2014/10/04/swift%20%E6%9D%A1%E4%BB%B6%E5%88%A4%E6%96%AD%E9%A1%B5%E9%9D%A2%E8%B7%B3%E8%BD%AC/ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |