Dismissing of UIImagePickerController dismisses presenting view controller also

Discussion in 'iOS Programming' started by santoshkc, Jun 30, 2016.

Tags:
  1. santoshkc, Jun 30, 2016
    Last edited: Jun 30, 2016

    santoshkc macrumors newbie

    santoshkc

    Joined:
    Jun 30, 2016
    Location:
    Kathmandu
    #1
    Hello, 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.
    Code in JobPostingViewController
    Code:
     @IBAction func openCreateJob(sender: AnyObject) {
            let vc = self.storyboard?.instantiateViewControllerWithIdentifier("CreateJobPostViewController") as! CreateJobPostViewController
            self.navigationController?.pushViewController(vc, animated: true)
        }
    
    code in CreateJobPostViewController
    Code:
    override func viewDidLoad() {
        super.viewDidLoad()
        imagePicker.delegate = self
    }
    //MARK:- IBActions
    @IBAction func addImages(sender: AnyObject) {
        imagePicker.allowsEditing = false
        imagePicker.sourceType = .PhotoLibrary 
        presentViewController(imagePicker, animated: true, completion: nil)
    }
    
    // this for did finish picker view controller
         func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
            picker.dismissViewControllerAnimated(true, completion: nil)
        }
    
    // for cancel picker view controller
    func imagePickerControllerDidCancel(picker: UIImagePickerController!)
    {
        picker.dismissViewControllerAnimated(true, completion: nil)
    }
     

    Attached Files:

  2. iphonedude2008 macrumors 65816

    iphonedude2008

    Joined:
    Nov 7, 2009
    Location:
    Irvine, CA
    #2
    I'm pretty sure you need to call - dismissViewControllerAnimated:: on the presenting view controller, which would be "self", not picker.
     

Share This Page