【问题标题】:How to set a UIImageView from a view controller called in with instantiateViewControllerWithIdentifier?如何从使用 instantiateViewControllerWithIdentifier 调用的视图控制器设置 UIImageView?
【发布时间】:2012-07-25 05:43:53
【问题描述】:

我正在使用情节提要,我需要使用子视图来导入 xib。 xib 只是显示图像。它有一个 UIImageView 和一个 UIBarButtonItem。将图像作为子视图导入后如何设置?

我尝试在 h+m 文件中为子视图 xib 设置方法,但也许我做错了。这是我的代码

-(void)showPreviewImageScreen:(UIImage *)image 
{

    UIStoryboard*  sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UIViewController* vc = [sb instantiateViewControllerWithIdentifier:@"libraryImagePreview"];

    [vc setPreviewImage:image];

    [self.navigationController.view addSubview:vc.view];

}

我得到的错误是“UIViewController 没有可见的@interface 声明选择器'setPreviewImage'”

【问题讨论】:

    标签: iphone objective-c xcode ios5


    【解决方案1】:

    没有一个名为 setPreviewImage 的方法(据我所知)。您使用 setImage: 设置图像,但这必须在您的 xib 中的 UIImageView 上调用,而不是在您的视图控制器 vc 上。

    【讨论】:

      【解决方案2】:

      @rdelmar 感谢您为我指明正确的方向.. 这是我想出的解决方案.. 我用 1 标记了 UIimageView,然后循环遍历子视图以找到该标记并以这种方式定位它。

      -(void)showPreviewImageScreen:(UIImage *)image 
      {
      
          UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
          UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"libraryImagePreview"];
      
      
          for (UIView *subview in vc.view.subviews)
          {
              if(subview.tag==1)
              {
                  UIImageView *IV = subview;
                  [IV setImage:image];
              }
          }
      
         [self.navigationController.view addSubview:vc.view];
      
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-09-19
        • 2013-12-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多