iPad UIImagePicker 问题!
我正在尝试从照片库导入图像,但是当我按下导入按钮时,程序崩溃并收到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您崩溃是因为您正在释放选择器,但没有保留它。您应该删除对
[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.
在 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