Bright Future Bright Future - 4 months ago 16
iOS Question

Using delegate error: cannot assign value of type

I'm trying to implement this framework from Github:
https://github.com/hyperoslo/ImagePicker

Then I created an

IBAction
in my view controller as described in the
Description
:

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UINavigationBarDelegate {

@IBAction func addMemory(sender: UIBarButtonItem) {

let imagePickerController = ImagePickerController()
imagePickerController.delegate = self //Error here
presentViewController(imagePickerController, animated: true, completion: nil)

}
}



Error: Cannot assign value of type 'MemoriesTable' to type
'ImagePickerDelegate?'

Answer

You should be implementing ImagePickerDelegate as well, because delegate is of type ImagePickerDelegate. Change as follow

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UINavigationBarDelegate, ImagePickerDelegate {

Make sure you implement protocol methods.

EDIT 1

You need to implement following methods of ImagePickerDelegate

public protocol ImagePickerDelegate: class {

   func wrapperDidPress(imagePicker: ImagePickerController, images: [UIImage])
   func doneButtonDidPress(imagePicker: ImagePickerController, images: [UIImage])
   func cancelButtonDidPress(imagePicker: ImagePickerController)
}
Comments