1

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
    present(imagePickerController, animated: true, completion: nil)

    }
}

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

Bright
  • 5,699
  • 2
  • 50
  • 72

4 Answers4

2

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)
}
Vishnu gondlekar
  • 3,896
  • 21
  • 35
  • Great! It works. But why don't I have to implement `tableViewController.delegate = self` ? – Bright Jul 14 '16 at 08:59
  • You might have done that in storyboard or xib itself while adding tableview. If you have not done that in storyboard then you have to set delegate and datasource in code, and implement the necessary protocol methods. – Vishnu gondlekar Jul 14 '16 at 09:01
  • I did as you said, but now there's a new error: Type 'ViewController' does not conform to protocol 'ImagePickerDelegate' – Bright Jul 14 '16 at 09:04
2

Revisit my own question 10 months later.

Simply change this line:

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UINavigationBarDelegate

to:

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UINavigationBarDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate

will make it work.

Bright
  • 5,699
  • 2
  • 50
  • 72
1

if you are implement the ImagePickerController then you need to add the following delegate UINavigationControllerDelegate,UIImagePickerControllerDelegate on your class

at the same time you need to implement the following delegate methods also

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
    imageView.contentMode = .ScaleAspectFit
    imageView.image = pickedImage
}

dismissViewControllerAnimated(true, completion: nil)
} 




func imagePickerControllerDidCancel(picker: UIImagePickerController)    {
dismissViewControllerAnimated(true, completion: nil)
}
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
0

Ive had similar issue. I realized picker.delegate = self was missing. Adding it fixed the issue

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

    var selectedImageFromPicker:UIImage?

    if let editedImage = info["UIImagePickerControllerOriginalImage"] as? UIImage{
        selectedImageFromPicker = editedImage
        print(editedImage.size)
    }



    else if let originalImage = info["UIImagePickerControllerOriginalImage"]  as? UIImage{
        selectedImageFromPicker = originalImage
        print(originalImage.size)

    }

    if let selectedImage = selectedImageFromPicker{
        Profileimg.image = selectedImage

    }
    dismiss(animated: true, completion: nil)

}