我以编程方式在 iOS Swift 项目中拥有多个 View Controller 。我没有 Storyboard,如果可能的话,我想避免使用它们。有没有办法切换到另一个 viewcontroller.swift 文件(我们称它为 view2.swift)并使其成为按钮调用的函数的一部分?
我尝试了以下方法:
let storyboard: UIStoryboard = UIStoryboard(name: "myTabBarName", bundle: nil)
let vc: UIViewController = storyboard.instantiateViewControllerWithIdentifier("myVCID") as UIViewController
self.presentViewController(vc, animated: true, completion: nil)
以上适用于 Storyboard,但我想调用另一个 view2.swift。这能做到吗?
最佳答案
试试这个:
let vc = ViewController() //change this to your class name
self.presentViewController(vc, animated: true, completion: nil)
使用 Swift3:
self.present(vc, animated: true, completion: nil)
关于 swift presentViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24099533/