1

ELCImagePickerController用来选择多张照片。但是,当我选择照片并单击完成按钮时,它会返回选择相册页面。请帮助我,所以当我选择照片时它应该返回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函数

4

2 回答 2

2

实际上我因为设置错误而面临这个问题delegate

在我的问题中,我设置delegate

picker.delegate = self

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

 picker.imagePickerDelegate = self
于 2015-06-30T04:55:06.127 回答
0

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

问题是我必须将 ELCimagepickerdelegate 添加到类中:

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

}
于 2016-11-27T05:54:44.133 回答