我有最初隐藏的图像视图。当我点击TakePhotoButton
然后它拍摄图像并将其指定给图像视图。然后图像视图可见。
当我调试代码时,即使productImg
不是nil,我的chosenImage
也始终为零。
@property (strong, nonatomic) IBOutlet UIImageView *productImg;
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.productImg.hidden=NO;
self.productImg.image=chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
答案 0 :(得分:1)
试试这个:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
__block MyViewController *aBlockSelf = self; // Replace MyViewController with your View Controller
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
[picker dismissViewControllerAnimated:YES completion:^{
aBlockSelf.productImg.hidden = NO;
aBlockSelf.productImg.image = chosenImage;
}];
}
答案 1 :(得分:0)
您使用以下代码它可能对您有所帮助。
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
{
UIImage *chosenImage = [info objectForKey:UIImagePickerControllerEditedImage];
self.productImg.hidden=NO;
self.productImg.image=chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
答案 2 :(得分:0)
为什么你最初必须隐藏它。因为图像将为null,所以不会看到它。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *chosenImage;
chosenImage= info[UIImagePickerControllerOriginalImage];
[self.productImg setImage:chosenImage];
[picker dismissViewControllerAnimated:YES completion:NULL];
}