-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info {
[self dismissModalViewControllerAnimated:YES];
UIImage *image = [info objectForKey: UIImagePickerControllerOriginalImage];
if(imageView1.image == nil){
imageView1.image = image;
}
else if(imageView2.image == nil){
imageView2.image = image;
}
else if(imageView3.image == nil){
imageView3.image = image;
}
//pickedImage = TRUE;
}
我有这个代码,它永远不会去第二个“if else”语句。 虽然它将图像分配给imageView1,但下次imageView1.image仍然为null。 我在这做错了什么?
提前致谢。
答案 0 :(得分:1)
我现在有两个解决方案。
1.试试这个
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
使用“ valueForKey ”代替 objectForKey
<强> 2 即可。在尝试对信息字典执行任何操作之前,必须先解除并释放UIImagePickerController。要非常明确:
这不起作用:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { myUIImageView.image = [info objectForKey:UIImagePickerControllerOriginalImage]; [picker dismissModalViewControllerAnimated:YES]; [picker release]; }
这将起作用
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [picker dismissModalViewControllerAnimated:YES]; [picker release]; myUIImageView.image = [info objectForKey:UIImagePickerControllerOriginalImage]; if(imageView1.image == nil){ imageView1.image = image; } else if(imageView2.image == nil){ imageView2.image = image; } else if(imageView3.image == nil){ imageView3.image = image; } }