2012-07-25 31 views
0

我正在使用故事板,我需要使用子視圖來導入xib。 xib只是顯示圖像。它有一個UIImageView和一個UIBarButtonItem。將圖像導入爲子視圖後,如何設置圖像?如何使用instantiateViewControllerWithIdentifier調用視圖控制器來設置UIImageView?

我試過在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’」

回答

0

沒有一個叫setPreviewImage方法(據我所知)。你用setImage設置圖像:但必須在你的xib中的UIImageView上調用,而不是在你的視圖控制器vc上。

0

@rdelmar感謝您指點我在正確的方向..這是我想出的解決方案.. 我標記了UIimageView 1,然後通過子視圖循環找到此標記並以此方式定位它。

-(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]; 

} 
相關問題