简体   繁体   English

UIImagePickerController没有将图像分配给uiimageview

[英]UIImagePickerController not assigning image to uiimageview

I am trying to use the UIImagePickerController and save the image to a UIImageView but it the image isn't saved? 我正在尝试使用UIImagePickerController并将图像保存到UIImageView,但是图像没有保存?

- (IBAction)handleAvatarTap:(id)sender {
DLog(@"");

UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

[picker dismissModalViewControllerAnimated:YES];
UIImage* original =[info objectForKey:@"UIImagePickerControllerOriginalImage"];

// This is the line that sets the image but the original image assigned to it is still there?
[self.avatarImage setImage:[UIImage imageWithCGImage:original.CGImage]];


}

Are you sure that avatarImage is init? 您确定avatarImage是init吗?

Something like: 就像是:

self.avatarImage = [[[UIImageView alloc] initWithFrame:myFrame] autorelease];
self.avatarImage.image = original;

将用户互动设置为已启用,现在可以使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM