On iPad, UIImagePickerController must be presented via UIPopoverController
2014-10-28 15:11
429 查看
<code><span class="kwd"><span style="font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; ">On iPad, UIImagePickerController must be presented via UIPopoverController 可以用以下方法来判断设备的类型选择不同的Controller</span></span></code>
<code><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">UI_USER_INTERFACE_IDIOM</span><span class="pun">()</span><span class="pln"> </span><span class="pun">==</span><span class="pln"> </span><span class="typ">UIUserInterfaceIdiomPhone</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">// We are using an iPhone</span><span class="pln"> </span><span class="typ">UIActionSheet</span><span class="pln"> </span><span class="pun">*</span><span class="pln">alertSheet </span><span class="pun">=</span><span class="pln"> </span><span class="pun">[[</span><span class="typ">UIActionSheet</span><span class="pln"> alloc</span><span class="pun">]</span><span class="pln"> initWithTitle</span><span class="pun">:@</span><span class="str">"Where do you want to get your daily image?"</span><span class="pln"> delegate</span><span class="pun">:(</span><span class="pln">self</span><span class="pun">)</span><span class="pln"> cancelButtonTitle</span><span class="pun">:@</span><span class="str">"Cancel"</span><span class="pln"> destructiveButtonTitle</span><span class="pun">:</span><span class="pln">nil otherButtonTitles</span><span class="pun">:@</span><span class="str">"Camera"</span><span class="pun">,</span><span class="pln"> </span><span class="pun">@</span><span class="str">"Library"</span><span class="pun">,</span><span class="pln"> nil</span><span class="pun">];</span><span class="pln"> </span><span class="pun">[</span><span class="pln">alertSheet setTag</span><span class="pun">:</span><span class="lit">0</span><span class="pun">];</span><span class="pln"> </span><span class="pun">[</span><span class="pln">alertSheet setDelegate</span><span class="pun">:</span><span class="pln">self</span><span class="pun">];</span><span class="pln"> </span><span class="pun">[</span><span class="pln">alertSheet showFromTabBar</span><span class="pun">:[[</span><span class="pln">self tabBarController</span><span class="pun">]</span><span class="pln"> tabBar</span><span class="pun">]];</span><span class="pln"> </span><span class="pun">[</span><span class="pln">alertSheet release</span><span class="pun">];</span><span class="pln"> </span><span class="pun">}</span><span class="kwd">else</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">// We are using an iPad</span><span class="pln"> </span><span class="typ">UIImagePickerController</span><span class="pln"> </span><span class="pun">*</span><span class="pln">imagePickerController </span><span class="pun">=</span><span class="pln"> </span><span class="pun">[[</span><span class="typ">UIImagePickerController</span><span class="pln"> alloc</span><span class="pun">]</span><span class="pln"> init</span><span class="pun">];</span><span class="pln"> imagePickerController</span><span class="pun">.</span><span class="pln">delegate </span><span class="pun">=</span><span class="pln"> self</span><span class="pun">;</span><span class="pln"> </span><span class="typ">UIPopoverController</span><span class="pln"> </span><span class="pun">*</span><span class="pln">popoverController</span><span class="pun">=[[</span><span class="typ">UIPopoverController</span><span class="pln"> alloc</span><span class="pun">]</span><span class="pln"> initWithContentViewController</span><span class="pun">:</span><span class="pln">imagePickerController</span><span class="pun">];</span><span class="pln"> popoverController</span><span class="pun">.</span><span class="pln">delegate</span><span class="pun">=</span><span class="pln">self</span><span class="pun">;</span><span class="pln"> </span><span class="pun">[</span><span class="pln">popoverController presentPopoverFromRect</span><span class="pun">:((</span><span class="typ">UIButton</span><span class="pln"> </span><span class="pun">*)</span><span class="pln">sender</span><span class="pun">).</span><span class="pln">bounds inView</span><span class="pun">:</span><span class="pln">sender permittedArrowDirections</span><span class="pun">:</span><span class="typ">UIPopoverArrowDirectionAny</span><span class="pln"> animated</span><span class="pun">:</span><span class="pln">YES</span><span class="pun">];</span><span class="pln"> </span><span class="pun">}</span></code>
<code><span class="pun"> </span></code>
<code><span class="pun"></span></code><p style="margin-top: 10px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px; background-color: rgb(248, 248, 248); text-indent: 28px; font-family: 宋体; line-height: 28px; "><span style="text-align: center; ">iPad</span>与<span style="text-align: center; ">iPhone</span>调用<span style="text-align: center; ">UIImagePickerViewController</span>方法略有不同是本文要介绍的内容,文中很详细的讲述了<span style="text-align: center; ">iPad</span>与<span style="text-align: center; ">iphone</span>各自的调用方法,来看详细内容。</p><p style="margin-top: 10px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px; background-color: rgb(248, 248, 248); text-indent: 28px; font-family: 宋体; line-height: 28px; ">我们知道,在<span style="text-align: center; ">iPhone</span>中获取照片库常用的方法如下:</p><pre style="white-space: pre-wrap; word-wrap: break-word; margin-top: 0px; margin-bottom: 1em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Courier New', monospace; width: 591.0166625976563px; overflow-x: auto; overflow-y: auto; background-color: rgb(230, 230, 230); line-height: 28px; "><ol class="dp-xml" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 55px; padding-top: 5px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; color: rgb(92, 92, 92); list-style-position: initial; word-wrap: break-word; word-break: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: rgb(247, 247, 247); "><li class="alt" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; color: inherit; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: break-word; word-break: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: transparent; line-height: 18px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; color: black; background-color: inherit; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: inherit; ">UIImagePickerController *</span><span class="attribute" style="color: red; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: inherit; ">m_imagePicker</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: inherit; "> = [[UIImagePickerController alloc] init]; </span></span></li><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: break-word; word-break: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: transparent; line-height: 18px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; color: black; background-color: inherit; "> if ([UIImagePickerController isSourceTypeAvailable: </span></li><li class="alt" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; color: inherit; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: break-word; word-break: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: transparent; line-height: 18px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; color: black; background-color: inherit; "> UIImagePickerControllerSourceTypePhotoLibrary]) { </span></li><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: break-word; word-break: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: transparent; line-height: 18px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; color: black; background-color: inherit; "> </span><span class="attribute" style="color: red; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: inherit; ">m_imagePicker.sourceType</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; color: black; background-color: inherit; "> = </span><span class="attribute-value" style="color: blue; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: inherit; ">UIImagePickerControllerSourceTypePhotoLibrary</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; color: black; background-color: inherit; ">; </span></li><li class="alt" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; color: inherit; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: break-word; word-break: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: transparent; line-height: 18px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; color: black; background-color: inherit; "> </span><span class="attribute" style="color: red; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: inherit; ">m_imagePicker.delegate</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; color: black; background-color: inherit; "> = </span><span class="attribute-value" style="color: blue; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: inherit; ">self</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; color: black; background-color: inherit; ">; </span></li><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: break-word; word-break: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: transparent; line-height: 18px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; color: black; background-color: inherit; "> // [m_imagePicker.navigationBar.subviews]; </span></li><li class="alt" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; color: inherit; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: break-word; word-break: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: transparent; line-height: 18px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; color: black; background-color: inherit; "> [m_imagePicker setAllowsEditing:NO]; </span></li><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: break-word; word-break: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: transparent; line-height: 18px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; color: black; background-color: inherit; "> //</span><span class="attribute" style="color: red; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: inherit; ">m_imagePicker.allowsImageEditing</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; color: black; background-color: inherit; "> = </span><span class="attribute-value" style="color: blue; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: inherit; ">NO</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; color: black; background-color: inherit; ">; </span></li><li class="alt" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; color: inherit; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: break-word; word-break: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: transparent; line-height: 18px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; color: black; background-color: inherit; "> [self presentModalViewController:m_imagePicker animated:YES]; </span></li><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: break-word; word-break: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: transparent; line-height: 18px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; color: black; background-color: inherit; "> [m_imagePicker release]; </span></li><li class="alt" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; color: inherit; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: break-word; word-break: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: transparent; line-height: 18px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; color: black; background-color: inherit; "> }else { </span></li><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: break-word; word-break: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: transparent; line-height: 18px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; color: black; background-color: inherit; "> UIAlertView *</span><span class="attribute" style="color: red; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: inherit; ">alert</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; color: black; background-color: inherit; "> = [[UIAlertView alloc]initWithTitle:nil message: </span></li><li class="alt" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; color: inherit; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: break-word; word-break: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: transparent; line-height: 18px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; color: black; background-color: inherit; ">@"Error accessing photo library!" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil]; </span></li><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: break-word; word-break: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: transparent; line-height: 18px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; color: black; background-color: inherit; "> [alert show]; </span></li><li class="alt" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; color: inherit; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: break-word; word-break: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: transparent; line-height: 18px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; color: black; background-color: inherit; "> [alert release]; </span></li><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: break-word; word-break: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; background-color: transparent; line-height: 18px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; color: black; background-color: inherit; "> } </span></li></ol>
这对iPhone的操作是没有问题的。但是当我们在iPad环境中却有问题了,当我们运行时会报如下错误:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'On iPad, UIImagePickerController must be presented via UIPopoverController'
所以我们必须通过UIPopoverController来实现才行。具体实现如下:
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]; }
这里需要注意,对局部UIPopoverController对象popover我们赋给了一个全局的UIPopoverController对象popoverController。而不能直接调用popover。因为在popover对象还可见时,是不能够被释放的。
小结:iPad与iphone调用UIImagePickerViewController方法略有不同的内容介绍完了,希望本文对你有所帮助!
相关文章推荐
- On iPad, UIImagePickerController must be presented via UIPopoverController
- On iPad, UIImagePickerController must be presented via UIPopoverController
- On iPad, UIImagePickerController must be presented via UIPopoverController
- On iPad, UIImagePickerController must be presented via UIPopoverController
- UIImagePickerController在iPhone和iPad中用法的一点不同
- IOS 在Ipad 横屏 上使用UIImagePickerController
- UIImagePickerController在iPhone和iPad上的区别
- UIImagePickerController在iPhone和iPad中用法的一点不同
- UIImagePickerController在iPhone和iPad中用法的一点不同
- UIImagePickerController在iPhone和iPad中用法的一点不同
- ios8.0 ipad UIImagePickerController
- Monotouch在IPAD与IPhone使用UIImagePickerController的图片选择不同的代码
- UIImagePickerController在iPhone和iPad上的区别
- UIImagePickerController在iPhone和iPad中用法的一点不同
- UIImagePickerController在iPhone和iPad中用法的一点不同[转]
- UIImagePickerController在UIPopoverController中 旋屏问题
- IOS6 UIImagePickerController在IPAD横屏闪退解决办法
- setObjectForKey: object cannot be nil (key: UIImagePickerControllerOriginalImage)
- UIImagePickerController隐藏statusBar
- 获得通过UIImagePickerController选取的图片的名称信息