UIImagePickerController在iPhone和iPad中用法的一点不同
来源:互联网 发布:log4js json格式 编辑:程序博客网 时间:2024/05/18 03:54
我们知道,在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对象还可见时,是不能够被释放的。
- UIImagePickerController在iPhone和iPad中用法的一点不同
- UIImagePickerController在iPhone和iPad中用法的一点不同
- UIImagePickerController在iPhone和iPad中用法的一点不同
- UIImagePickerController在iPhone和iPad中用法的一点不同
- UIImagePickerController在iPhone和iPad中用法的一点不同
- UIImagePickerController在iPhone和iPad中用法的一点不同
- UIImagePickerController在iPhone和iPad上的区别
- UIImagePickerController在iPhone和iPad上的区别
- 在 iPad和 iPhone的浏览器上查看网页源代码
- Yamli阿拉伯语翻译带来的应用程序在iPhone和iPad
- iPhone和iPad的图标
- iPhone和iPad的图标
- ios storyboard中 iphone 和iPad 之间的转换方式
- 在iPhone/iPad工程中设置常量
- iOS 如何 分别为 iPad 和 iPhone 建立 不同的 storyboard
- ios 编程: ipad 和 iphone开发中使用 UIWebView 来播放视频的时候,在页面切换时 停止播放
- ios 编程: ipad 和 iphone开发中使用 UIWebView 来播放视频的时候,在页面切换时 停止播放
- 【iOS奇葩特性】layoutSubviews在iPhone和iPad中,当设备方向改变后的调用情况
- unix环境高级编程----标准I/O库
- Android实现推送方式解决方案
- 在GitHub上分享和展示你的代码
- Difference between Do_Key('Exit_Form') and Exit_Form
- Oracle Dataguard Switchover
- UIImagePickerController在iPhone和iPad中用法的一点不同
- 电脑蓝屏了怎么办?
- asp.net 关于 web.config详解
- Android XML属性介绍
- 一个简单的多线程例子-临界区
- DataDirectory是什么?
- 将 Win32 C/C++ 应用程序迁移到 POWER 上的 Linux
- Redhat 5.5 yum 安装配置KVM
- 理解subView,手动实现多个视图切换