Search code examples
swiftelcimagepickercontroller

elcimagepickercontroller in swift


I am using xcode 7.2 and Swift 2.1.1. I am using ELCImagePickerController through bridging header. When I use ELCImagePickerControllerDelegate in class declaration,it shows error- the viewcontroller does not conform to protocol 'ELCImagePickerControllerDelegate'

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

This is my objective c header #import "ELCImagePickerController.h"

When I use this code on button click event it goes to empty view and not the gallery.Can anyone help me to overcome this error.

Thanks in advance.


Solution

  • Error - the viewcontroller does not conform to protocol 'ELCImagePickerControllerDelegate' because you have to implement below 2 delegate methods which are mandatory. ( Not optional )

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

    Download whole working project

    Working code

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

    That black screen were coming because of

    var picker = ELCImagePickerController()
    

    Proper way is

    var picker = ELCImagePickerController(imagePicker: ())