iam尝试从照片库导入图像,但是当我按下导入按钮程序崩溃并收到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];
}
答案 0 :(得分:2)
你正在崩溃,因为你正在释放选择器,但是你没有保留它。您应该删除对[picker release]
的调用。
您应该切换到使用所有ivars的访问器。访问者和dealloc通常是您应该保留或释放您的ivars的唯一地方。选择器不是你的ivar而你没有创建它,所以你根本不应该发布它。
你应该花一些时间与Memory Management Programming Guide。您可以在Three Magic Words获得简短版本。
答案 1 :(得分:1)
在iPad iOS 3.2上,UIImagePickerController必须以 popover 呈现,而不是模态视图。