我正在尝试从Github实现这个框架: https://github.com/hyperoslo/ImagePicker
然后我按照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)
}
}
中所述在我的视图控制器中创建了@interface BaseViewController : UIViewController
-(void) backPreviousScreen;
:
#import "BaseViewController.h"
@interface LoginViewController : BaseViewController
错误:无法指定“MemoriesTable”类型的值进行输入 'ImagePickerDelegate?'
答案 0 :(得分:2)
您也应该实现ImagePickerDelegate
,因为委托的类型为ImagePickerDelegate
。改变如下
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UINavigationBarDelegate, ImagePickerDelegate {
确保实施协议方法。
编辑1
您需要实施ImagePickerDelegate
public protocol ImagePickerDelegate: class {
func wrapperDidPress(imagePicker: ImagePickerController, images: [UIImage])
func doneButtonDidPress(imagePicker: ImagePickerController, images: [UIImage])
func cancelButtonDidPress(imagePicker: ImagePickerController)
}
答案 1 :(得分:2)
10个月后再次回顾我自己的问题。
只需更改此行:
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UINavigationBarDelegate
为:
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UINavigationBarDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate
将使其发挥作用。
答案 2 :(得分:1)
如果你实现了ImagePickerController
,那么你需要在你的类上添加以下代理 UINavigationControllerDelegate,UIImagePickerControllerDelegate
同时您还需要实现以下委托方法
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)
}
答案 3 :(得分:0)
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)
}