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 它只占用部分屏幕空间来 ...
随机推荐
- Android——edittext的几个属性
<EditText android:layout_columnSpan="2" android:hint="To" android:layout_grav ...
- 路由表及route使用
路由表 linux下通过route可以查看本地路由表: Kernel IP routing table Destination Gateway Genmask ...
- Windows Server 2008组策略安全实践(同样适用于域控制)
Windows Server 2008系统的安全功能非法强大,而它的强大之处不仅仅是新增加了一些安全功能,而且还表现在一些不起眼的传统功能上.对Windows Server 2008系统的组策略功能进 ...
- JVM 详谈
JVM 详谈 本来这次应该讲讲ORM 的几个框架,但是笔者还没有完全总结出来,所以这里先插入一次学习JVM的心得.作为一个Java程序员,如果不了解JVM的工作原理,就很难从底层去把 握Java语言和 ...
- Entity Framework应用:Code First的实体继承模式
Entity Framework的Code First模式有三种实体继承模式 1.Table per Type (TPT)继承 2.Table per Class Hierarchy(TPH)继承 3 ...
- Entity Framework实体拆分
一.概念 实体拆分:一个实体拆分成多个表,如Product实体,可以拆分成Product和ProductWebInfo两个表,Product表用于存储商品的字符类信息,ProductWebInfo用于 ...
- 关于Cocos2d-x中精灵节点的透明度的设置
1.当我们需要某个精灵作为一个大一点的容器来存放其他的小精灵的时候,我们先设置这个精灵的大小 setTextureRect(Rect(0, 0, babySize.width, babySize.he ...
- 如何查询表A中的某字段的值在表B中不存在?
1.测试表创建,插入数据: create table a (id int, name )); create table b (id int); ,'a'); ,'b'); ,'c'); ,'d'); ...
- 【转】7Z命令行解压缩
7z.exe在CMD窗口的使用说明如下: 7-Zip (A) 4.57 Copyright (c) 1999-2007 Igor Pavlov 2007-12-06 Usage: 7za <co ...
- 第二百九十八节,python操作redis缓存-Set集合类型,可以理解为不能有重复元素的列表
python操作redis缓存-Set集合类型,可以理解为不能有重复元素的列表 sadd(name,values)name对应的集合中添加元素 #!/usr/bin/env python # -*- ...