iOS Take photo from camera problem
I've a problem with taking a photo with the iphone camera. I have following code:
- (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 = 开发者_如何学PythonUIImagePickerControllerSourceTypePhotoLibrary;
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];
}
I found the problem. If I tested it with the debugger, i saw following:
If I take a photo from the camera roll it works fine. All references of self are available. So the program can set the image.
But if I take a photo with the camera, all references of self (imageBtn p.e.) are not available, so the program cannot set the image.
What is my error?
Thanks for the answer
rob
I do not know why you are overriding the setImage method of UIButton
you could have actually said
[self.imageBtn setImage:newImg forState:UIControlStateNormal];
First of all your imageBtn is not available, Here your imageBtn initialized when you load the ProfileCompletion01 so are you releasing it somewhere? you can use the awakeFromNib method for your UItableViewCell to initialize the imageBtn again.
精彩评论