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 ( vc 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/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值