展示另一个View Controller

时间:2019-04-22 08:15:08

标签: swift

let VC = storyboard?.instantiateViewController(withIdentifier: "PapersMenu")
    VC?.modalTransitionStyle = .flipHorizontal
        self.present(VC!, animated: true, completion: nil)

我正在使用上面的代码来呈现一个新的ViewController。我将情节提要ID设置为“ PapersMenu”

我想要做的是,当用户单击表视图中的任何表单元格时,我希望将用户转发到一个名为“ PapersMenu”的ViewController。 但是代码不起作用。

1 个答案:

答案 0 :(得分:0)

也许您尝试在某些非UIViewController类中调用present方法,因此您的代码将无法工作。

let sb : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let VC = sb.instantiateViewController(withIdentifier: "PapersMenu")

self.present(VC!, animated: true, completion: nil) // where self is subclass of `UIViewController`.

或使用另一个viewController

let rootController = (UIApplication.shared.delegate?.window!!.rootViewController)!
rootController.present(VC!, animated: true, completion: nil) // when you try to call `present` method in some class, which is not subclass of `UIViewController`.