CreateJobPostViewController

CreateJobPostViewController

我正在使用选项卡系统的项目上工作。标签栏的一项是JobPostingViewController。我将其嵌入到UINavigationController中。这个 View Controller 中有一个名为添加新作业的UIButton。我实现了pushviewcontroller来执行CreateJobPostViewController。在那里,我需要添加UIImagePickerController来选择图像。当我点击“完成”按钮或从库中选择图像时,它将解散到JobPostingViewController。但它应该转到CreateJobPostViewController。
任何人请帮助我。提前致谢。

您可以在这里看到问题:
ios - 消除UIImagePickerController也会消除呈现 View  Controller-LMLPHP

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)
}

最佳答案

将选择器添加为 subview

尝试将imagepicker作为 subview 添加到创建它的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()
    }

用于呈现

在当前上下文中显示选择器,并提供诸如“编辑取消”,“选择”,“

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

 presentViewController(picker, animated: true, completion: nil)

10-07 19:49
查看更多