IPadAndIPhoneCallUIImagePickerViewControllerThe method is slightly different from the content described in this article.IPadAndIphoneFor details.
We know thatIPhoneTo obtain the Photo Library in the following ways:
- UIImagePickerController *m_imagePicker = [[UIImagePickerController alloc] init];
- if ([UIImagePickerController isSourceTypeAvailable:
- UIImagePickerControllerSourceTypePhotoLibrary]) {
- m_imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
- m_imagePicker.delegate = self;
- // [m_imagePicker.navigationBar.subviews];
- [m_imagePicker setAllowsEditing:NO];
- //m_imagePicker.allowsImageEditing = NO;
- [self presentModalViewController:m_imagePicker animated:YES];
- [m_imagePicker release];
- }else {
- UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:
- @"Error accessing photo library!" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
- [alert show];
- [alert release];
- }
This is no problem with iPhone operations. However, when we encounter problems in the iPad environment, the following error will be reported during running:
- Terminating app due to uncaught exception 'NSInvalidArgumentException',
- reason: 'On iPad, UIImagePickerController must be presented via UIPopoverController'
Therefore, we must use UIPopoverController. The specific implementation is as follows:
- UIImagePickerController *m_imagePicker = [[UIImagePickerController alloc] init];
- if ([UIImagePickerController isSourceTypeAvailable:
- UIImagePickerControllerSourceTypePhotoLibrary]) {
- m_imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
- m_imagePicker.delegate = self;
- [m_imagePicker setAllowsEditing:NO];
- UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:m_imagePicker];
- self.popoverController = popover;
- //popoverController.delegate = self;
-
- [popoverController presentPopoverFromRect:CGRectMake(0, 0, 300, 300) inView:self.
- view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
-
- //[self presentModalViewController:m_imagePicker animated:YES];
- [popover release];
- [m_imagePicker release];
- }else {
- UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"Error accessing photo library!"
- delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
- [alert show];
- [alert release];
- }
Note that a global UIPopoverController object popoverController is assigned to the partial UIPopoverController object popopovercontroller. Instead, you cannot directly call pover. Because popover objects cannot be released when they are still visible.
Summary:IPadAndIphoneCallUIImagePickerViewControllerThe method is slightly different. I hope this article will help you!