Я пытаюсь заставить свое приложение получить фотографию из пользовательской библиотеки фотографий с помощью UIImagePickerController и отобразить ее в приложении. Мой код прекрасно работает для iPhone, но мне нужно использовать UIPopoverController для iPad. Я все еще очень плохо разбираюсь в программировании, поэтому мне очень трудно понять, как это сделать. Во время тестирования я столкнулся со странной ошибкой. Отладчик говорит: « Завершение приложения из-за необработанного исключения« NSGenericException », причина:« - [UIPopoverController dealloc] достигнут, пока всплывающее окно все еще видно. », но я ничего не освобождаю, у меня включен ARC. Вот мой код:
ViewController.m:
#import "PhotoViewController.h"
@implementation PhotoViewController
@synthesize grabButton;
@synthesize image;
@synthesize imgPicker;
- (IBAction)grabImage {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:imgPicker];
[popover presentPopoverFromRect:self.image.bounds inView:self.image permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
} else {
[self presentModalViewController:imgPicker animated:YES];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
image.image = img;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
- (void)viewDidLoad
{
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.allowsImageEditing = YES;
self.imgPicker.delegate = self;
self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
Любая помощь очень ценится! Спасибо!