UIImagePickerController在iPhone和iPad中用法的一点不同
2012-06-15 19:36
411 查看
UIImagePickerController在iPhone和iPad中用法的一点不同
2010-12-02 17:04 2033人阅读 评论(6) 收藏 举报
我们知道,在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中用法的一点不同
2010-12-02 17:04 2033人阅读 评论(6) 收藏 举报我们知道,在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中用法的一点不同
- Monotouch在IPAD与IPhone使用UIImagePickerController的图片选择不同的代码
- UIImagePickerController在iPhone和iPad上的区别
- UIImagePickerController在iPhone和iPad上的区别
- iphone:使用UIImagePickerController从IPhone照片库或照相机获取图像
- UIImagePickerController 的部分用法详解
- UIImagePickerController用法
- UIImagePickerController 图像选取器--在iPhone中调用照相机、照片库—IOS开发
- 【iPhone】UIImagePickerController 查看图片,视频,录像
- 【iPhone】UIImagePickerController 查看图片,视频,录像
- UIImagePickerController的基础用法
- UIImagePickerController PAD /IPHONE 上注意事项
- iphone UIImagePickerController组件图片旋转问题
- On iPad, UIImagePickerController must be presented via UIPopoverController
- 使用UIImagePickerController从iPhone照片库或照相机获取图像
- iphone 怎么使用图片选取器 UIImagePickerController