UIImagePickerController在iPhone和iPad中用法的一点不同

UIImagePickerController在iPhone和iPad中用法的一点不同,第1张

概述源自:http://huchenqiang90.blog.163.com/blog/static/1125008002011018416051/ 我们知道,在iPhone中获取照片库常用的方法如下: UIImagePickerController *m_imagePicker = [[UIImagePickerController alloc] init];     if ([UIImagePic

源自:http://huchenqiang90.blog.163.com/blog/static/1125008002011018416051/


我们知道,在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,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对象还可见时,是不能够被释放的。

@H_502_44@ 总结

以上是内存溢出为你收集整理的UIImagePickerController在iPhone和iPad中用法的一点不同全部内容,希望文章能够帮你解决UIImagePickerController在iPhone和iPad中用法的一点不同所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1093980.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存