
概述在iPhone中获取照片库的常用方法如下: UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceType
在iPhone中获取照片库的常用方法如下: UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotolibrary]) { imagePicker.sourceType = UIImagePickerControllerSourceTypePhotolibrary; imagePicker.delegate = self; [imagePicker setAllowsEditing:NO]; [self presentModalVIEwController:imagePicker animated:YES]; [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来实现才行。具体的实现如下:
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentVIEwController:imagePicker]; self.popoverController = popover; [popoverController presentPopoverFromrect:CGRectMake(0, 300,0)">300) inVIEw:self.vIEw permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; [popover release]; }
转自:http://2015.iteye.com/blog/1340797 总结
以上是内存溢出为你收集整理的UIImagePickerController在iPhone和iPad上的区别全部内容,希望文章能够帮你解决UIImagePickerController在iPhone和iPad上的区别所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
评论列表(0条)