2015-10-06 66 views
0

我有最初隱藏的圖像視圖。當我點擊TakePhotoButton,然後它拍攝圖像並將其分配給圖像視圖。那麼圖像視圖是可見的。將拍攝的圖像指定給圖像view.image

當我調試我的代碼時,我總是得到我的productImg爲零,儘管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

'productImg'解析到圖像視圖時NIB負荷,所以它什麼都沒有做使用此方法。它看起來像一個綁定IB與出口的錯誤。 – Droppy

+0

是productImg一個IBOutlet或你在哪裏分配imageView –

+0

YE ProductImage是一個ImageView IBoutlet – hotspring

回答

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; 
    }]; 
} 
+0

這仍然是同樣的問題。 – hotspring

+1

您可以請仔細檢查您的'productImg'是否正確添加到視圖。可以嘗試通過最初不隱藏一次並在其上設置任何隨機圖像。 – Abhinav

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]; 
} 
+0

我提供的解決方案有什麼區別? – hotspring

0

爲什麼你要隱藏它initially.Since圖像將是空的就不會看到任何如何。

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

      chosenImage= info[UIImagePickerControllerOriginalImage]; 
      [self.productImg setImage:chosenImage]; 
      [picker dismissViewControllerAnimated:YES completion:NULL]; 

}