Calling uiimagepickerviewcontroller on iPad is slightly different from calling iphoen.

Source: Internet
Author: User



We know that the following methods are commonly used to obtain the photo library from the iPhone:

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 presentpoverfromrect: cgrectmake (0, 0,300,300) inview: Self. View permittedarrowdirections ctions: 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.

 

This article Reprinted from: http://blog.csdn.net/fxj281314




 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.