我正在iOS 5上使用UIImagePickerController与我的应用程序被拒绝,因为它在他们的终端崩溃了。它不会崩溃,但我确信它与UIPopoverController有关。
请指出看起来很糟糕的事情!
显示UIImagePickerController:
- (IBAction)photoLibraryiPad {
if (popoverController) {
if ([self.popoverController isPopoverVisible]) {
[self.popoverController dismissPopoverAnimated:YES];
[popoverController setDelegate:nil];
[popoverController release];
}
} else {
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.allowsEditing = YES;
self.popoverController = [[UIPopoverController alloc]
initWithContentViewController:imagePicker];
popoverController.delegate = self;
[self.popoverController presentPopoverFromRect:photolibrarybutton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[imagePicker release];
}
}
}
然后这就是它们最终崩溃的地方:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
if ([self.popoverController isPopoverVisible]) {
[self.popoverController dismissPopoverAnimated:YES];
[popoverController setDelegate:nil];
[popoverController release];
}
[noimageAvailable setHidden:YES];
UIImage *originalImage = (UIImage *) [info objectForKey:
UIImagePickerControllerEditedImage];
[imgPic setImage:originalImage forState:UIControlStateNormal];
// Hide picker selector
[picker dismissModalViewControllerAnimated: YES];
[picker release];
}
答案 0 :(得分:2)
两件事:
1)释放弹出窗口时,应将委托设置为nil。在致电popoverController.delegate = nil
之前[popoverController release]
。如果您尝试多次使用选择器,它可能会崩溃。委托正在调用一个不再存在的对象。
2)检查弹出窗口是否可见时,检查以确保它是否存在。