ELCImagePickerController does not back to viewController in swift

淺唱寂寞╮ 提交于 2019-12-13 02:14:44

问题


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


回答1:


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



回答2:


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

}


来源:https://stackoverflow.com/questions/30883871/elcimagepickercontroller-does-not-back-to-viewcontroller-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!