iPad UIImagePicker 问题!

发布于 2024-09-18 16:24:11 字数 1123 浏览 4 评论 0原文

我正在尝试从照片库导入图像,但是当我按下导入按钮时,程序崩溃并收到 SGIBART!但我的代码在 iPhone 上运行良好,为什么?

这是我的代码:

.h:

@interface CameraViewController : UIViewController <UIImagePickerControllerDelegate ,UINavigationControllerDelegate> {

    UIImagePickerController *ipc;
    UIImageView * image1;

@property (.......................;
}

.m:

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {



    image1.image = [[info objectForKey:UIImagePickerControllerOriginalImage]retain];
    [[picker parentViewController]dismissModalViewControllerAnimated:YES];
    [picker release];   

}


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

    [[picker parentViewController]dismissModalViewControllerAnimated:YES];
    [picker release];


}



        -(IBAction) importImage1 {

    ipc = [[UIImagePickerController alloc]init];
    ipc.delegate = self;
    ipc.sourceType =  UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:ipc animated:YES];
}

iam trying import an image from photos library but when i press the import button program crashes and received SGIBART !! but my code works fine on iPhone why ?

here is my code :

.h :

@interface CameraViewController : UIViewController <UIImagePickerControllerDelegate ,UINavigationControllerDelegate> {

    UIImagePickerController *ipc;
    UIImageView * image1;

@property (.......................;
}

.m :

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {



    image1.image = [[info objectForKey:UIImagePickerControllerOriginalImage]retain];
    [[picker parentViewController]dismissModalViewControllerAnimated:YES];
    [picker release];   

}


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

    [[picker parentViewController]dismissModalViewControllerAnimated:YES];
    [picker release];


}



        -(IBAction) importImage1 {

    ipc = [[UIImagePickerController alloc]init];
    ipc.delegate = self;
    ipc.sourceType =  UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:ipc animated:YES];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧情别恋 2024-09-25 16:24:11

您崩溃是因为您正在释放选择器,但没有保留它。您应该删除对[picker release]的调用。

您应该转而对所有 ivars 使用访问器。通常,访问器和 dealloc 是您应该保留或释放 ivars 的唯一位置。 picker 不是你的 ivar 并且你没有创建它,所以你根本不应该释放它。

您应该花一些时间阅读内存管理编程指南。您可以在三个魔词获取简短版本。

You're crashing because you're releasing picker, but you didn't retain it. You should remove the calls to [picker release].

You should switch to using accessors for all of your ivars. Accessors and dealloc are generally the only places you should retain or release your ivars. picker is not your ivar and you didn't create it, so you shouldn't be releasing it at all.

You should spend some time with the Memory Management Programming Guide. You can get the short version at Three Magic Words.

不交电费瞎发啥光 2024-09-25 16:24:11

在 iPad iOS 3.2 上,UIImagePickerController 必须以 popover 形式呈现,而不是作为模态视图。

检查一下:
http://www.cocos2d-iphone.org/forum/topic/6108

On the iPad iOS 3.2 a UIImagePickerController must be presented in a popover, not as a modal view.

check this out :
http://www.cocos2d-iphone.org/forum/topic/6108

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文