On iPad, UIImagePickerController must be presented via UIPopoverController
本文转载至:http://blog.csdn.net/k12104/article/details/8537695
On iPad, UIImagePickerController must be presented via UIPopoverController 可以用以下方法来判断设备的类型选择不同的Controller
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone){// We are using an iPhoneUIActionSheet*alertSheet =[[UIActionSheet alloc] initWithTitle:@"Where do you want to get your daily image?" delegate:(self) cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Camera",@"Library", nil];[alertSheet setTag:0];[alertSheet setDelegate:self];[alertSheet showFromTabBar:[[self tabBarController] tabBar]];[alertSheet release];}else{// We are using an iPadUIImagePickerController*imagePickerController =[[UIImagePickerController alloc] init];
imagePickerController.delegate = self;UIPopoverController*popoverController=[[UIPopoverController alloc] initWithContentViewController:imagePickerController];
popoverController.delegate=self;[popoverController presentPopoverFromRect:((UIButton*)sender).bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];}
iPad与iPhone调用UIImagePickerViewController方法略有不同是本文要介绍的内容,文中很详细的讲述了iPad与iphone各自的调用方法,来看详细内容。
我们知道,在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];
- }
这对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的更多相关文章
- iOS:iPad和iPhone开发的异同(UIPopoverController、UISplitViewController)
iPad和iPhone开发的异同 1.iPhone和iPad: niPhone是手机,iPad.iPad Mini是平板电脑 iPhone和iPad开发的区别 屏幕的尺寸 \分辨率 UI元素的排布 \ ...
- IOS成长之路-调用照相机和相册功能
打开相机: //先设定sourceType为相机,然后判断相机是否可用(ipod)没相机,不可用将sourceType设定为相片库 UIImagePickerControllerSourceType ...
- iPad 控件 UIPopoverPresentationController 使用 iPhone可用
UIPopoverController 在iOS9之后被废弃了,,, iOS8 新控件UIPopoverPresentationController可运用在iphone和iPad上,使用基本同 UIP ...
- BlocksKit的使用
一.引言 众所周知Block已被广泛用于iOS编程.它们通常被用作可并发执行的逻辑单元的封装,或者作为事件触发的回调.Block比传统回调函数有2点优势: 允许在调用点上下文书写执行逻辑,不用分离函数 ...
- IOS 在Ipad 横屏 上使用UIImagePickerController
转载前请注明来源:http://www.cnblogs.com/niit-soft-518/p/4381328.html 最近在写一个ipad的项目,该项目必须是横屏.进入正题,有一项功能是要调用系统 ...
- iPad 控件UIPopoverController使用
UIPopoverController 是iPad特有控件,(iOS7-9),在iOS9之后别废弃 使用步骤 设置内容控制器 UIPopoverController直接继承NSObject,不具备可视 ...
- iOS iPad开发之UIPopoverController的使用
1. 什么是UIPopoverController? 是iPad开发中常见的一种控制器(在iphone上不允许使用) 跟其他控制器不一样的是,它直接继承自NSObject,并非继承自UIViewCon ...
- iOS8 iPad Warning: Attempt to present <UIImagePickerController:xxxx > on xxxx which is already presenting (null)
解决方法: /* I think this is because in iOS 8, alert views and action sheets are actually presented view ...
- iPad开发中UIPopoverController的使用
什么是UIPopoverController 是iPad开发中常见的一种控制器 跟其他控制器不一样的是,它直接继承自NSObject,并非继承自UIViewController 它只占用部分屏幕空间来 ...
随机推荐
- web应用中文乱码问题的原因分析
为了让使用Java语言编写的程序能在各种语言的平台下运行,Java在其内部使用Unicode字符集来表示字符,这样就存在Unicode字符集和本地字符集进行转换的过程.当在Java中读取字符数据的时候 ...
- uboot中fb实现
帧缓冲区fb在内存中,要实现fb同步显示需要设定DMA操作. 设定LCD的DMA操作,要在开始操作LCD之前. common/lcd.c中定义lcd_init() --> driver/vide ...
- jffs2根文件系统制作
http://www.eetop.cn/blog/html/98/510998-20964.html 作者:刘洪涛,华清远见嵌入式学院高级讲师,ARM公司授权ATC讲师. JFFS2是Flash上应用 ...
- Golang map 如何进行删除操作?
Cyeam 关注 2017.11.02 10:02* 字数 372 阅读 2784评论 0喜欢 3 map 的删除操作 Golang 内置了哈希表,总体上是使用哈希链表实现的,如果出现哈希冲突,就把冲 ...
- Node.js连接postgres
一.下载Node.js postgres驱动 Node.js里面没有postgres模块的,我们需要安装node-postgres模块. node-postgres模块的下载地址为:https://g ...
- 实现对DataGird控件的绑定操作
//实现对DataGird控件的绑定操作 function InitGrid(queryData) { $('#grid').datagrid({ //定位到Table标签,Table标签的ID是gr ...
- sparkr——报错
> sc <- sparkR.init() Re-using existing Spark Context. Please stop SparkR with sparkR.stop() o ...
- Windows 10恢复Shift+右键打开命令提示符窗口
导入以下注册表即可. Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directory\Background\shell\cmd1] ...
- thinkphp3.2 常用入口文件
<?php define('DIR_SECURE_FILENAME', 'default.html'); define('APP_PATH','./index/'); //项目路径 requir ...
- TensorFlow基础笔记(0) tensorflow的基本数据类型操作
import numpy as np import tensorflow as tf #build a graph print("build a graph") #生产变量tens ...