最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]Swift代码方式动态地跳转切换页面的方式

Swift crifan 4703浏览 0评论
[背景]
折腾了:
之后,觉得有必要去:
搞清楚,swift中,代码的,动态的,方式去切换,跳转页面的方式有哪几种。
否则不清楚的话,以后还会出现类似的:
对于之前几层页面view,用的是
self.presentViewController(对应页面返回方式是dismissViewControllerAnimated)
去显示的
而后期再调用
pushViewController(对应的页面返回方式是popViewControllerAnimated)
[折腾过程]
1.搜:
swift programmatically switch view
参考:
2.搜:
swift programmatically switch view not use storyboard
参考:
提到了:
presentViewController
showViewController
3.搜:
swift presentViewController
参考:
4.然后去研究:presentViewController
搜:
ios presentViewController
参考:
5.再去搜:
iOS showViewController
参考:
[总结]
Swift中用代码实现页面切换的写法:
(1)一种写法是:
let vc = ViewController() //change this to your class name
self.presentViewController(vc, animated: true, completion: nil)
或:

vc : ViewController =  ViewController(nibName: “ViewController”, bundle: nil) //change this to your class name
 self.presentViewController(vc, animated: true, completion: nil)
(2)用了storyboard:
var vc = self.storyboard?.instantiateViewControllerWithIdentifier(“myVCId”) as MyVCName
self.presentViewController(vc, animated: true, completion: nil)
或:
 let vc : AnyObject! = self.storyboard.instantiateViewControllerWithIdentifier(“billInfo”)
        self.showViewController(vc as UIViewController, sender: vc)
或:
let storyboard = UIStoryboard(name: “myStoryboardName”, bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier(“nextViewController”) as UIViewController
presentViewController(vc, animated: true, completion: nil)
(3)用了导航栏的:
let vc = ViewController()
var navigationController = UINavigationController(rootViewController: vc)
self.presentViewController(navigationController, animated: true, completion: nil
(4)而很久之前的代码,好像还会用到那个Segue:
self.performSegueWithIdentifier(“signInView”, sender: self)
然后:
推荐的是:
我们不需要使用 (事实上 iOS 8 后 Apple 也不再提倡使用) UINavigationController 的 pushViewController:animated: 方法了
我们现在有了新的展示 viewController 的方法,
-showViewController:sender:
(以及-showDetailViewController:sender:)
-》以后尽量都改用showViewController(或showDetailViewController)

转载请注明:在路上 » [已解决]Swift代码方式动态地跳转切换页面的方式

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.169 seconds, using 22.18MB memory