Swift3.0中如何完成不同View Controller之间的切换

来源:互联网 发布:淘宝自动提取卡密 编辑:程序博客网 时间:2024/05/17 02:52

在网上看过一些关于View Controller之间的切换的介绍,但是由于我使用的是swift3.0,所以在一些语法上面有写不同,但是思路还是一样的。下面是我整理的一些关于swift3.0中View Controller之间的切换的一些心得。这个介绍的是普通View之间的跳转,还有一类跳转是关于NavigationController,需要另外介绍。

主要分为两种情况:

1切换到纯代码建好的view controller,即不是在storyboard中建立的:

//Application 文件下
let guideViewController = GuideViewController()self.window!.rootViewController=guideViewController

//普通ViewControllerlet VC = LoginController()self.present(VC, animated: true, completion:nil)

   2切换到在storyboard中建立的可以用下面的代码:

let mainStoryboard = UIStoryboard(name:"Main", bundle:nil)        let viewController = mainStoryboard.instantiateViewController(withIdentifier: "LoginView")        self.present(viewController, animated: true, completion:nil)
这里的LoginView是在storyboard中对相应的viewcontroller打开其identifier inspector,然后对其storyboard ID起的名字。


0 0