ELCImagePickerController 在 swift 中不返回 viewController

ELCImagePickerController does not back to viewController in swift

我用ELCImagePickerController来select多张照片。但是,当我 select 照片并单击“完成”按钮时,它会返回到 select 相册页面。请帮助我,所以当我 select 照片它应该回到 viewController

这是我使用的代码:

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

编辑:当我调试代码时它从不调用didFinishPickingMediaWithInfo函数

实际上我遇到这个问题是因为错误地设置了 delegate

在我的问题中,我将 delegate 设置为

picker.delegate = self

这是错误的。正确的做法是设置 ELCImagepickerDelegate

 picker.imagePickerDelegate = self

我解决了 - 在下面找到完整的最终工作代码 -

问题是我必须将 ELCimagepickerdelegate 添加到 class 中,如下所示:

class ViewController: UIViewController, UINavigationControllerDelegate, ELCImagePickerControllerDelegate {

但是我以前每次这样做都会遇到错误(类型 viewcontroller 不符合协议),所以解决方案是忽略此错误,直到我在代码中添加下面的 2 个委托方法(这阻止了错误,这非常令人困惑 - 对不起,我是 swift 的新手。感谢大家试图帮助

整个工作代码:

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

}