Swift present 与 push 跳转问题
2017-01-04 17:00
155 查看
Swift 使用presentViewController 跳转页面后显示黑屏
原因:storyboard 制作页面 和 纯代码页面,需要使用两种不同方法进行页面跳转Storyboard 界面:使用代码跳转
let sb = UIStoryboard(name: "Main", bundle:nil) let vc = sb.instantiateViewControllerWithIdentifier("SecondViewController") as! SecondViewController self.presentViewController(vc, animated: true, completion: nil)
注意:记得要设置 StoryboardID ,可以在 Identifier inspector 中修改
StoryboardID
纯代码界面
//present方式 let vc = SecondViewController() self.presentViewController(vc, animated: true, completion: nil) // 转场动画风格 modalTransitionStyle
Modal 方式转场一般使用在几个没有共同样式的控制器之间。
如果有共同样式的话,大都数用 navigation控制器和 tabBar控制器来实现。
//push方式 self.navigationController.pushViewController(vc, animated:true)
扩展 naviagation //push方式
如果是同个栈的控制器 需要弹出到指定界面:
//弹回根视图 self.navigationController?.popToRootViewControllerAnimated(true) //指定位置 self.navigationController?.popToViewController((self.navigationController?.viewControllers[0])!, animated: true)
SB与代码结合 ,使用SB连接时候,多条连线传值问题
//使用SB连接转场每次都会触发下面方法 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { //可再每个连线处类似按钮的东西加上identifier,即可判断不同指向 if segue.identifier == "segueIdentifier" { //不带导航的方式 let vc = segue.destinationViewController as! nextVC //下个视图前了带了导航的方式 //let nv_vc = segue.destinationViewController.childViewControllers[0] as! nextVC } }
文/逗牛(简书作者)
原文链接:http://www.jianshu.com/p/376274daea82
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
相关文章推荐
- present和push混用,再跳转回来的问题
- 页面跳转问题,多次 push 到新的页面的问题的解决方法
- StoryBoard使用push跳转不连线。(解决黑屏问题)
- ios pushViewController 页面不跳转问题解决
- 当push跳转时隐藏了tabBar,pop后tabBar消失的问题
- weex通过navigator.push的方式跳转页面,页面不显示问题
- 小白使用react——解决this.props.history.push无法跳转的问题
- iOS push跳转页面时,页面透明交叉的问题。
- [绍棠_Swift] Swift3.0中 通过viewController push跳转到TabbarController 隐藏后退按钮问题
- 页面间的跳转问题
- error-page 跳转失效问题
- 关于锚点页内链接跳转出现问题(不响应,没有反应)的解决方法(ZT)
- FireFox中location跳转问题
- Push模式下水晶报表的若干问题
- cn.errorsafe.com网页自动跳转的问题
- [转]在Asp.net中弹出对话框,然后跳转到其他页面问题
- 页面跳转 传递中文问题
- 框架跳转问题
- iframe1 跳转问题
- JSP页面跳转中的问题