呈现一个ViewController,将其关闭,然后进入另一个View

时间:2016-09-15 08:02:01

标签: ios swift uiimagepickercontroller

我正在尝试执行以下操作:

  1. 用户按下按钮
  2. 弹出
  3. UIImagePickerController
  4. 用户选择图片
  5. UIImagePickerController被驳回
  6. 闯入另一个ViewController
  7. 截至目前,我已经设置了当用户按下按钮时,初始化UIImagePickerController并使用presentViewController进行呈现。它也被委托给该按钮链接的类。用户选择图像后,将调用imagePickerController,并且还会调用dismissViewControllerAnimated。然后,调用performSegueWithIdentifier。但是,最后一步会抛出以下警告,然后不会发出警告:

      

    2016-09-15 03:45:44.870食物日记[9941:1540144]警告:尝试出席        在谁的视图不在窗口层次结构!

    我是Swift和iOS开发的新手,这是什么意思,我该如何解决?

3 个答案:

答案 0 :(得分:4)

完成解雇UIImagePickerController

后执行segue
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
    // your code
    self.dismissViewControllerAnimated(true, completion: {
        self.performSegueWithIdentifier("SegueIdentifier", sender: self)
    })
}

注意:对于发件人,我已经通过了当前的Controller对象,您可以使用任何对象。

答案 1 :(得分:0)

尝试在呈现和贬低视图控制器时使用这两行代码

演示:

self.view.window.rootviewcontroller.presentViewController("yourVC",animated:true, nil)

诋毁:

self.view.window.rootViewController.dismissViewController(animated:true completion:nil)

答案 2 :(得分:0)

它停留在同一个ViewController上,因为UIImagePickerController仍在视图层次结构中,第二个ViewController无法添加到UIImagePickerController之上。要解决这个问题,你需要在完成UIImagePickerCopntroller解雇时包装你的segue:

self.dismiss(animated: true, completion: {
    self.performSegue(withIdentifier: "StartToMain", sender: nil)
})