我正在使用Image picker Controller来拍照并将它们保存到数据库中。我有这种方法来获取相机拍摄的图像。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
此方法在被委派为self时自动调用。当我点击一个按钮时,我试着打电话给这个,但是我无法获得图像。它显示为null。这是我调用picker控制器委托方法的方法。
- (IBAction)save_Image:(id)sender {
UIImagePickerController *saveDelegate;
NSDictionary *infoDelegate;
[self imagePickerController:(saveDelegate) didFinishPickingMediaWithInfo:(infoDelegate)];
UIImage *chosenImage = infoDelegate[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
//here i couldn't get the image. I am getting null
}
有没有办法通过我自己的方法调用该方法来获取图像?
答案 0 :(得分:1)
如果您想通知其他人用户选择图片的时间,这是使用通知的理想场所。
static NSString* const ImagePickerDidFinishPickingPhotoNotification = @"ImagePickerDidFinishPickingPhotoNotification";
@implementation MyViewController
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[[NSNotificationCenter defaultCenter] postNotificationName:ImagePickerDidFinishPickingPhotoNotification
object:picker
userInfo:info];
}
@end