【发布时间】:2015-04-24 04:06:05
【问题描述】:
我在 UIViewController 之前设置了 NavigationViewcontroller,我想以编程方式执行 segue 并将另一个 Viewcontroller 推送到导航堆栈上。我怎样才能做到这一点?
class CreateEventViewController: UIViewController, CLLocationManagerDelegate {
// Updated post with simple answer
// If you have a Naviagation Controller already instantiated then all you have to do is perform segue and it will push it on the navigation stack for you
self.performSegueWithIdentifier("Event Creation Success", sender: nil)
}
编辑:
我的故事板图片http://imgur.com/rgbNxI1
【问题讨论】:
-
如果您使用的是 segue,那么您不应该在代码中推送视图控制器。
-
@rdelmar 当我按下按钮时会发生这种情况,但按下按钮时会执行其他操作。我想在该代码执行后继续。
-
您需要从控制器而不是按钮中进行转场。在按钮的action方法中,在segue之前执行需要运行的代码,然后调用performSegueWithIdentifier。除非您将数据传递给 FindHelpViewController,否则您根本不应该实现 prepareForSegue。
-
@rdelmar 感谢您的澄清,不知道 prepareForSegue 仅用于在控制器之间传递数据。你知道我如何实例化我的导航控制器,以便我可以将我的视图控制器推到它上面吗?
-
你在问题中说你已经有了一个导航控制器,为什么还要实例化一个新的?
标签: ios swift uiviewcontroller uinavigationcontroller