如何在Swift中以编程方式从一个控制器导航到另一个视图控制器?

时间:2018-05-12 17:41:06

标签: ios swift uitableview uinavigationcontroller

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "GMNewPostControllerSegueIdentifier"
    {
        let svc = segue.destination as? UINavigationController

        let vc: GMNewPostController = svc?.topViewController as! GMNewPostController
    }
}

@IBAction func newPostButtonAction(_ sender: UIButton) {
     performSegue(withIdentifier: "GMNewPostController", sender: self)
}

我不想从我的故事板中拖放,因为我在vc2中有一个表格视图。

1 个答案:

答案 0 :(得分:0)

Check below image , storyboard should like this

并参考Action for button并像这样写

For button Action