使用iphone相机拍照时遇到问题。我有以下代码:
- (IBAction)openCamera {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (IBAction)openCameraRoll {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
UIImage *img = image;
Image *imgHelp = [[Image alloc] init];
UIImage *newImg = [imgHelp imageByScalingProportionallyToSize:CGSizeMake(220, 220) image:img];
[self setImage:newImg];
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
- (void)setImage:(UIImage*)i {
[imageBtn setImage:i forState:UIControlStateNormal];
}
我发现了问题。如果我用调试器测试它,我看到了以下内容:
如果我从相机胶卷拍照,它可以正常工作。所有自我引用均可用。 所以程序可以设置图像。
但如果我用相机拍照,所有自我引用(imageBtn p.e.)都不可用,因此程序无法设置图像。
我的错误是什么?
感谢您的回答
抢劫
答案 0 :(得分:0)
我不知道为什么要覆盖UIButton的setImage方法
你原本可以说
[self.imageBtn setImage:newImg forState:UIControlStateNormal];
首先你的imageBtn不可用,你在加载ProfileCompletion01时初始化了你的imageBtn所以你在某处释放它吗? 您可以使用UItableViewCell的awakeFromNib方法再次初始化imageBtn。