如何在 iOS 中以编程方式将图像传递给视图控制器?
How to pass an image to a view controller programatically in iOS?
我尝试将图像传递给视图控制器,如下所示,
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];
使用它可以很好地呈现给所需的视图控制器。但是我设置的图像并没有添加到图像视图中。有没有什么办法解决这一问题?为什么会这样?
提前致谢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 的视图层次结构未设置
我尝试将图像传递给视图控制器,如下所示,
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];
使用它可以很好地呈现给所需的视图控制器。但是我设置的图像并没有添加到图像视图中。有没有什么办法解决这一问题?为什么会这样?
提前致谢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 的视图层次结构未设置