elcimagepickercontroller在swift中

时间:2016-11-29 07:02:40

标签: swift elcimagepickercontroller

我正在使用xcode 7.2和Swift 2.1.1。我通过桥接头使用ELCImagePickerController。当我在类声明中使用ELCImagePickerControllerDelegate时,它显示错误 - viewcontroller不符合协议'ELCImagePickerControllerDelegate'

let picker = ELCImagePickerController() picker.maximumImagesCount = 5
picker.delegate = self self.presentViewController(picker, animated: true, completion: nil)

这是我的目标c标题#import "ELCImagePickerController.h"

当我在按钮点击事件上使用此代码时,它会转到空视图而不是图库。任何人都可以帮助我克服此错误。

提前致谢。

1 个答案:

答案 0 :(得分:1)

错误 - viewcontroller不符合协议'ELCImagePickerControllerDelegate',因为您必须实现以下2个必需的委托方法。 (不是可选的)

func elcImagePickerController(picker: ELCImagePickerController!, didFinishPickingMediaWithInfo info: [AnyObject]!) {

}


func elcImagePickerControllerDidCancel(picker: ELCImagePickerController!) {

}

Download whole working project

工作代码

import UIKit


class ViewController: UIViewController, ELCImagePickerControllerDelegate {

    var picker = ELCImagePickerController(imagePicker: ())

    override func viewDidLoad() {
        super.viewDidLoad()

    }


    override func viewDidAppear(animated: Bool) {

        picker.maximumImagesCount = 5
        picker.imagePickerDelegate = self
        self.presentViewController(picker, animated: true, completion: nil)


    }

    func elcImagePickerController(picker: ELCImagePickerController!, didFinishPickingMediaWithInfo info: [AnyObject]!) {

    }


    func elcImagePickerControllerDidCancel(picker: ELCImagePickerController!) {

    }


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


}

黑屏因为

而来了
var picker = ELCImagePickerController()

正确的方法是

var picker = ELCImagePickerController(imagePicker: ())

有一个快乐的编码。