swift 页面跳转

iOS开发中界面跳转有两种方式,上下跳转和左右跳转。

上下跳转_TO:

let secondViewController = SecondViewController()

self.presentViewController(secondViewController,animated:true,completion:nil)

上下跳转_BACK:

dismissViewControllerAnimated(true,completion:nil)

-----------------------------------------------

-----------------------------------------------

左右跳转_TO:

(将新的视图控制器PUSH到navigationController中,相当于入栈操作)

let secondViewController = SecondViewController()

self.navigationController!.pushViewController(secondViewController,animated:true)

左右跳转_BACK:

(将当前视图控制器从导航视图控制器堆栈中移除,从而返回到了上一级界面)

( - ) BACK_到上一级:

let firstViewController = FirstViewController()

self.navigationController?.popViewControllerAnimated(true)

( - )BACK_指定界面:

// 获得视图控制器中的某一视图控制器

let viewController =self.navigationController?.viewControllers[0]

self.navigationController?.popToViewController(viewController as! UIViewController,animated:true)

( - )BACK_根视图:

self.navigationController?.popToRootViewControllerAnimated(true)

根视图的设置需要在AppDelegate中设置:

varwindow: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptionslaunchOptions: [NSObject:AnyObject]?) -> Bool

{

var firstViewController = FirstViewController()

var rootNavigationViewController = UINavigationController(rootViewController: firstViewController)

self.window!.rootViewController= rootNavigationViewController

returntrue

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • iOS开发中界面跳转有两种方式,上下跳转和左右跳转。 上下跳转_TO: letsecondViewControll...
    A嗄嗄阅读 3,788评论 0 1
  • 刚学iOS编程时候,最基本的页面跳转其实让人非常揪心,没有一个完整的介绍跳转思路的文章,导致看着各种各样的跳转非常...
    Wanto阅读 1,052评论 0 1
  • *7月8日上午 N:Block :跟一个函数块差不多,会对里面所有的内容的引用计数+1,想要解决就用__block...
    炙冰阅读 2,579评论 1 14
  • 你我皆凡人,生在人世间。 终日奔波苦,一刻不得闲。 既然不是仙,难免有杂念。 以下文字是看完《你有什么可能》、《暗...
    Dr_52Hz阅读 290评论 0 0
  • 本篇是Swift4中Codable的使用系列第二篇,继上一篇文章,我们学习了Codable协议在json与模型之间...
    砖头很烫手阅读 5,225评论 2 11