概述UIImagePickerController在iPhone和iPad中
用法的一点不同 我们知道,在iPhone中获取照片库常用的方法如下: UIImagePickerController *m_imagePicker = [[UIImagePickerControlleralloc] init]; if([UIImagePickerController isSourceTypeAvail UIImagePickerController在iPhone和iPad中用法的一点不同
我们知道,在iPhone中获取照片库常用的方法如下: UIImagePickerController *m_imagePicker = [[UIImagePickerControlleralloc] 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;
[selfpresentModalVIEwController:m_imagePicker animated:YES];
[m_imagePicker release];
}else{
UIAlertVIEw*alert = [[UIAlertVIEw alloc]initWithTitle:nil message:@"Erroraccessing photo library!" delegate:nil cancelbuttonTitle:@"Close"otherbuttonTitles:nil];
[alertshow];
[alertrelease];
} 这对iPhone的 *** 作是没有问题的。但是当我们在iPad环境中却有问题了,当我们运行时会报如下错误: Terminating app due to uncaught exception'NSInvalIDArgumentExcepti
on',reason: 'On iPad,UIImagePickerController must be presented viaUIPopoverController' 所以我们必须通过UIPopoverController来实现才行。具体实现如下: UIImagePickerController *m_imagePicker = [[UIImagePickerControlleralloc] 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,300,300) inVIEw:self.vIEwpermittedArrowDirections:UIPopoverArrowDirectionAnyanimated:YES]; //[selfpresentModalVIEwController:m_imagePicker animated:YES]; [popoverrelease]; [m_imagePicker release]; }else{ UIAlertVIEw*alert = [[UIAlertVIEw alloc]initWithTitle:nil message:@"Erroraccessing photo library!" delegate:nil cancelbuttonTitle:@"Close"otherbuttonTitles:nil]; [alertshow]; [alertrelease]; } 这里需要注意,对局部UIPopoverController对象popover我们赋给了一个全局的UIPopoverController对象popoverController。而不能直接调用popover。因为在popover对象还可见时,是不能够被释放的。 总结
以上是内存溢出为你收集整理的UIImagePickerController在iPhone和iPad中用法的一点不同全部内容,希望文章能够帮你解决UIImagePickerController在iPhone和iPad中用法的一点不同所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
评论列表(0条)