我有一个带有 2 个 ViewController 的故事板,第一个 ViewController 有一个按钮可以从相册中选择一张照片。第二个 ViewController 有一个 ImageView。结果是黑屏。
这是委托方法:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:NO completion:nil];
UIImage * selectedIMG = [info objectForKey:UIImagePickerControllerOriginalImage];
VCImageEditingViewController *ieVC = [self.storyboard instantiateViewControllerWithIdentifier:@"VCImageEditingViewController"];
ieVC.selectedIMG = selectedIMG;
[self presentViewController: ieVC animated:NO completion:nil];
}
在 VCImageEditingViewController.m 中:
-(void)loadView
{
if (self.selectedIMG) {
self.imageDisplayed.image = self.selectedIMG;
}
else{
UIImage *image = [UIImage imageNamed:@"hat.jpg"];
self.imageDisplayed.image = image;
}
}
即使我在这两种情况下更改 if 语句以显示“帽子”照片,它也会显示黑屏,所以我很确定它与图像选择器有关。
感谢您的帮助。