ios - 从另一个方法调用图像选择器 Controller 委托(delegate)方法

标签 ios objective-c uiimagepickercontroller

我正在使用图像选择器 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/

相关文章:

隐藏 View 时的 iOS 布局更改

iphone - 使用自定义键盘调用 textFieldShouldReturn

ios - 我如何组织这些数据?

ios - UITableView 中的两个不同的 UITableViewCell

iphone - iOS Storyboard 模态序列和内存

ios - 从弹出窗口打开全屏模式时,相机的屏幕位置不正确

iphone - UIImagePickerController 浏览多个 View 并打开相机后相机取消不起作用?

ios - 快速更改图像选择器首选状态栏样式

ios - viewDidLoad 在 prepareForSegue 完成之前调用

ios - 此处不允许使用 CoreDatato-many 键的关系