我正在使用图像选择器 Controller 拍照并将它们保存到数据库中。我有这种方法来获取相机拍摄的图像。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
此方法被自动调用,因为它被委托(delegate)为 self。当我单击一个按钮时,我试图调用它,但我无法获取图像。它向我显示 null。这是我调用选择器 Controller 委托(delegate)方法的方法。
- (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
}
是否有任何可能的方法可以通过从我自己的方法调用该方法来获取图像?
最佳答案
如果您想在用户选择图像时通知其他人,这是使用通知的理想场所。
static NSString* const ImagePickerDidFinishPickingPhotoNotification = @"ImagePickerDidFinishPickingPhotoNotification";
@implementation MyViewController
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[[NSNotificationCenter defaultCenter] postNotificationName:ImagePickerDidFinishPickingPhotoNotification
object:picker
userInfo:info];
}
@end
关于ios - 从另一个方法调用图像选择器 Controller 委托(delegate)方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27104987/