【问题标题】:PrepareForSegue does not work for function that will jump to different view controllerPrepareForSegue 不适用于将跳转到不同视图控制器的功能
【发布时间】:2016-11-07 20:11:29
【问题描述】:

所以我有 2 个 VC。在 Sending VC 中,我想将数据发送到 Receive VC。在制作 UIButton 时,我在其他项目中通过 PrepareForSegue 做到了这一点。这很完美。 但是现在我创建了一个函数,当满足条件时会跳转到那个 VC。函数如下:

let vc = self.storyboard?.instantiateViewControllerWithIdentifier("Resultsviewcontroller") as! Resultsviewcontroller
let navigationController = UINavigationController(rootViewController: vc)
self.presentViewController(navigationController, animated: false, completion: nil)

它将跳转到 VC,但不会跳转到我在 PrepareForSegue 函数中声明的数据。如何使用 PrepareForSegue 之类的函数发送数据?

另外,当跳转到接收VC时,它的顶部有一条白线。看起来状态栏应该在那里,但在两个 VC 中,我将其设置为“无”。我怎样才能去掉那条白线?

【问题讨论】:

    标签: swift viewcontroller


    【解决方案1】:

    在您的情况下,您不再通过调用presentViewController 来使用segue 呈现控制器,您可以做的是,如果您的segue 存在于情节提要中,并且两个控制器之间有一个segue 标识符,您可以调用它以编程方式使用performSegueWithIdentifier 函数。

    如果不存在,您可以手动设置 segue 并使用函数performSegueWithIdentifier 启动它。您可以从这个答案中受益 How do I create a segue that can be called from a button that is created programmatically?

    希望对你有所帮助。

    【讨论】:

    • 很好,你帮了我。这就是答案: dispatch_async(dispatch_get_main_queue()) { [unowned self] in self.performSegueWithIdentifier("Test", sender: self) } 这实际上也解决了我的另一个问题!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-22
    相关资源
    最近更新 更多