应用程序崩溃在imagePickerController中:UIImagePickerController内的didFinishPickingMediaWithInfo方法

时间:2012-01-23 05:48:54

标签: iphone objective-c ios uiimagepickercontroller

我是iOS开发的初学者,我试图让应用程序从UIImagePicker控件中选择一个显示在UIImageView对象中的图像。我面临的问题是这个方法

-(void)imagePickerController:(UIImagePickerController*)Picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
    NSLog(@"Inside dismiss modal view delegate 2");
    UIImage * image = [info objectForKey:UIImagePickerControllerOriginalImage];
    selectedImage.image = [image retain];
    NSLog(@"Inside the did pickerController method");
}

当我从UIImagePickerController中选择图像时,图像被选中但应用程序崩溃。我尝试调试,第一个NSLog语句显示在控制台上,但第二个没有显示。

我正在尝试从模拟器中的照片库加载图像。我使用的是XCode 3.2.5,模拟器是4.2。这可能是两个NSLog语句之间存在错误。但是,我尽力找出错误,但没有任何成功。你能帮帮我吗?

1 个答案:

答案 0 :(得分:3)

NSData *dataImage = UIImageJPEGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"],1);
imgPicture.image = [[UIImage alloc] initWithData:dataImage];
[picker dismissModalViewControllerAnimated:YES];

将此代码放入方法