我检查了几个教程,据我所知我的代码是正确的,但最后我没有得到图像。我没有收到任何错误,但我尝试设置的屏幕上的图像仍然是空白的。
这是我的头文件
@interface homeViewController : UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *avatarImage;
@property (weak, nonatomic) IBOutlet UIButton *photoButton;
@property (nonatomic, retain) UIImagePickerController *imgPicker;
- (IBAction)setPhoto;
@end
这是相关的方法
- (IBAction)setPhoto
{
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.sourceType=UIImagePickerControllerSourceTypeCamera;
self.imgPicker.delegate=self;
self.imgPicker.allowsEditing = YES;
self.imgPicker.showsCameraControls=YES;
[self presentModalViewController:self.imgPicker animated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
self.avatarImage = [[UIImageView alloc] init];
self.avatarImage.image = image;
[self dismissModalViewControllerAnimated:YES];
}
当我在这里放置断点时:[self dismissModalViewControllerAnimated:YES]; 我看到 image 变量有一个值,但是 self.avatarImage 有一个 0x00000000