ios – 解雇UIImagePickerController也会解散呈现视图控制器

我正在开发一个使用tabbar系统的项目. tabbar项之一是JobPostingViewController.我将它嵌入UINavigationController中.在这个视图控制器中有一个名为add new job的UIButton.我实现了pushviewcontroller去CreateJobPostViewController.在那里我需要添加UI ImagePickerController来选择图像.当我点击完成按钮或从库中选择一个图像时,它会关闭到JobPostingViewController.但它应该去CreateJobPostViewController.
任何人请帮助我.提前致谢.

你可以在这里看到问题:

JobPostingViewController中的代码

@IBAction func openCreateJob(sender: AnyObject) {
    let vc = self.storyboard?.instantiateViewControllerWithIdentifier("CreateJobPostViewController") as! CreateJobPostViewController
    self.navigationController?.pushViewController(vc,animated: true)
}

CreateJobPostViewController中的代码

@IBAction func addImages(sender: AnyObject) {
    imagePicker.allowsEditing = false
    imagePicker.sourceType = .PhotoLibrary
    presentViewController(imagePicker,animated: true,completion: nil)
}
func imagePickerController(picker: UIImagePickerController,didFinishPickingMediawithInfo info: [String : AnyObject]) {
    picker.dismissViewControllerAnimated(true,completion: nil)
}
func imagePickerControllerDidCancel(picker: UIImagePickerController) {
    picker.dismissViewControllerAnimated(true,completion: nil)
}

解决方法

将Picker添加为子视图

尝试将imagepicker作为子视图添加到您的CreateJobPostViewController中,然后将其从代理中的父项中删除

@IBAction func openCreateJob(sender: AnyObject) {

var picker: UIImagePickerController = UIImagePickerController()
picker.delegate = self
picker.allowsEditing = false
picker.sourceType = .PhotoLibrary
self.addChildViewController(picker)
picker.didMovetoParentViewController(self)
self.view!.addSubview(picker.view!)
}

然后

func imagePickerControllerDidCancel(picker: UIImagePickerController) {

    picker.view!.removeFromSuperview()
    picker.removeFromParentViewController()
    }

用于呈现

通过currentcontext显示选择器,例如编辑取消选择,

在演示之前使用picker.modalPresentationStyle = .overCurrentContext //

presentViewController(picker,completion: nil)

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...