ELCImagePickerController不会在swift中返回viewController

时间:2015-06-17 06:34:05

标签: ios objective-c swift elcimagepickercontroller

我使用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函数

2 个答案:

答案 0 :(得分:2)

实际上我因为错误地设置了let strLast5: String = textView.text.substringToIndex(countElements(textView.text) - 5); 而面临这个问题。

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

delegate

哪个错了。正确的方法是设置picker.delegate = self

ELCImagepickerDelegate

答案 1 :(得分:0)

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

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

class ViewController: UIViewController, UINavigationControllerDelegate, ELCImagePickerControllerDelegate {

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

整个工作代码:

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

}