0

在研究了 UIImagePickerController 之后,我得到了这个代码来从弹出窗口中选择一个图像,然后在 myParticularImageView 中显示它。

这是 ViewController.m:

@interface ViewController () {
UIImagePickerController *imagePickerController;
UIPopoverController *popover;
}
@end

- (IBAction)chooseImageButtonPressed:(id)sender {

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[popover setDelegate:self];
[popover presentPopoverFromRect:((UIButton *)sender).frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

//then to dismiss the popover and display pic
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[[self myParticularImageView] setImage:image];
[popover dismissPopoverAnimated:YES];
}
@end

我遇到的问题是,当我从弹出窗口中点击图片时,什么也没有发生。

在 .h 我得到:

:UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIPopoverControllerDelegate>

什么可能导致我的问题,我该如何解决?

4

1 回答 1

1

您不是图像选择器委托,这就是您没有使用委托方法的原因。

需要补充:[imagePicker setDelegate:self];在创建时的某个时候。

于 2013-05-14T15:26:04.227 回答