解雇UIImagePickerController也会解散呈现视图控制器 [英] Dismissing of UIImagePickerController dismisses presenting view controller also
问题描述
我正在开发一个使用tabbar系统的项目。 tabbar项之一是JobPostingViewController。我将它嵌入UINavigationController中。在这个视图控制器中有一个名为add new job的UIButton。我实现了pushviewcontroller去CreateJobPostViewController。在那里我需要添加UIImagePickerController来选择图像。当我点击完成按钮或从库中选择一个图像时,它会关闭到JobPostingViewController。但它应该去CreateJobPostViewController。
任何人请帮助我。在此先感谢。
I am working on a project that uses tabbar system. One of the item of tabbar is JobPostingViewController. I Embed it in UINavigationController. There is a UIButton called add new job in this view controller .I implemented pushviewcontroller to go CreateJobPostViewController. There I need to add UIImagePickerController to choose the image. When i tap done button or choose an image from library it dismisses to JobPostingViewController. But it should go to the CreateJobPostViewController. Any one please help me. Thanks in advance.
您可以在此处查看问题:
You can see the issue here:
JobPostingViewController中的代码
Code in JobPostingViewController
@IBAction func openCreateJob(sender: AnyObject) {
let vc = self.storyboard?.instantiateViewControllerWithIdentifier("CreateJobPostViewController") as! CreateJobPostViewController
self.navigationController?.pushViewController(vc, animated: true)
}
CreateJobPostViewController中的代码
Code in 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添加为子视图
Adding Picker as subview
尝试将imagepicker作为子视图添加到CreateJobPostViewController ins中提交它然后从委托中的父项中删除它
try to add the imagepicker as a subview to your CreateJobPostViewController insted of presenting it and then remove it from parent in the delegtes
@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()
}
用于展示
For presenting
在currentcontext上显示选择器,其中包括编辑取消选择,
showing picker over currentcontext with options like edit cancel choose,
使用 picker.modalPresentationStyle = .overCurrentContext
//在呈现
之前
use picker.modalPresentationStyle = .overCurrentContext
//before presenting
it
presentViewController(picker, animated: true, completion: nil)
这篇关于解雇UIImagePickerController也会解散呈现视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!