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://blog.csdn.net/tpian928/article/details/43115253

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/

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...