【问题标题】:How to pass an image to a view controller programatically in iOS?如何在 iOS 中以编程方式将图像传递给视图控制器?
【发布时间】:2015-02-10 10:59:57
【问题描述】:

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

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

【问题讨论】:

  • vc.image nil?
  • 不。这不是零..

标签: ios objective-c uiviewcontroller storyboard


【解决方案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 的视图层次结构没有设置

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-15
    • 1970-01-01
    • 2014-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-09
    • 1970-01-01
    相关资源
    最近更新 更多