如何在iOS中以编程方式将图像传递给视图控制器?

时间:2015-02-10 10:59:57

标签: ios objective-c uiviewcontroller storyboard

我试图将图像传递给视图控制器,如下所示,

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPad" bundle:nil];
CropViewController *vc = (CropViewController*)[storyboard instantiateViewControllerWithIdentifier:@"CropViewController"];
vc.imageView.image = [UIImage imageWithData:jpegData];
// present
[self presentViewController:vc animated:YES completion:nil];

使用它可以很好地呈现给所需的视图控制器。但是我设置的图像,它没有添加到图像视图中。有没有什么办法解决这一问题?为什么会这样?

感谢Advance1

1 个答案:

答案 0 :(得分:1)

应该是:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPad" bundle:nil];
CropViewController *vc = (CropViewController*)[storyboard instantiateViewControllerWithIdentifier:@"CropViewController"];
// present
[self presentViewController:vc animated:YES completion:(^{
    vc.imageView.image = [UIImage imageWithData:jpegData];
})];

未设置VC的视图层次结构