所以我有一个 iPhone 应用程序可以选择和图像,然后出现一个弹出窗口。您可以选择取消弹出框,这会关闭弹出框,这是以下方法的作用。当我测试我的应用程序时,我可以从照片库中选择一张图片,让图片选择器被关闭,但随后 imagePicker 又回来了。但是,当我测试我的应用程序时,没有打印以下方法的注释,并且我没有在其他地方实现 dimiss 调用,所以这怎么可能发生???
- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
if ([popoverController isPopoverVisible]) {
NSLog(@"imagePickerControllerDidCancel called for iPad");
[popoverController dismissPopoverAnimated:YES];
}
}
else {
NSLog(@"imagePickerControllerDidCancel called for iPhone");
[self dismissViewControllerAnimated:YES completion:nil];
}
[picker release];
[self pickImage];
}
用于呈现视图控制器的代码:
switch (buttonIndex) {
case 0: { //photo library
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
if ([popoverController isPopoverVisible]) {
[popoverController dismissPopoverAnimated:YES];
}
else {
popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
popoverController.delegate = self;
[popoverController presentPopoverFromRect:CGRectMake( 250, -50, 320, 480 )
inView:[self view]
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
}
}
else {
[self presentViewController:imagePicker animated:TRUE completion:nil];
}
} else {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Photo library is empty or unavailable" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
break;
}