Rizwan Shaikh
Rizwan Shaikh

Reputation: 2904

ELCImagePickerController does not back to viewController in swift

I useELCImagePickerController to select multiple photos. However when i select photos and click Done button its goes back to select an album page. Please help me so when i select photos it should back to viewController .

Here is code i using:

var picker = ELCImagePickerController(imagePicker: ())
 @IBAction func ButtonIsclick(sender: AnyObject) {
    picker.delegate = self

    self.presentViewController(picker, animated: true, completion: nil)
}

func elcImagePickerController(picker: ELCImagePickerController!, didFinishPickingMediaWithInfo info:[AnyObject]!) {
    self.dismissViewControllerAnimated(true, completion: nil)
}

func elcImagePickerControllerDidCancel(picker: ELCImagePickerController!){
    self.dismissViewControllerAnimated(true, completion: nil)
}

EDIT: When i debug the code its never call the didFinishPickingMediaWithInfo function

Upvotes: 1

Views: 1319

Answers (2)

rania
rania

Reputation: 57

I solved it - find below the complete final working code -

The problem was I had to add ELCimagepickerdelegate to the class to be as:

class ViewController: UIViewController, UINavigationControllerDelegate, ELCImagePickerControllerDelegate {

however I used to get an error (Type viewcontroller does not conform to protocol) every time I do this, so the solution was to ignore this error until I add the 2 delegate methods below in my code (that stopped the error, which was very confusing - sorry I am new to swift. thanks to everybody tried to help

Whole working Code:

import UIKit
import ELCImagePickerController

class ViewController: UIViewController, UINavigationControllerDelegate, ELCImagePickerControllerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

var picker = ELCImagePickerController()
    @IBAction func OpenPhotos(_ sender: AnyObject) {

       picker.imagePickerDelegate = self
        self.present(picker, animated: true, completion: nil)

    }



    func elcImagePickerController(_ picker: ELCImagePickerController!, didFinishPickingMediaWithInfo info: [Any]!) {
        dismiss(animated: true, completion: nil)
    }

    func elcImagePickerControllerDidCancel(_ picker: ELCImagePickerController!) {
        dismiss(animated: true, completion: nil)
    }

}

Upvotes: 0

Rizwan Shaikh
Rizwan Shaikh

Reputation: 2904

Actually i face this problem because of wrongly set the delegate.

In my question i set delegate as

picker.delegate = self

Which is wrong . Right way is to set ELCImagepickerDelegate is

 picker.imagePickerDelegate = self

Upvotes: 2

Related Questions