![](/img/trans.png)
[英]IBAction to set UIImageview image in second View Controller?
[英]How to set a UIImageView from a view controller called in with instantiateViewControllerWithIdentifier?
我正在使用情節提要,並且需要使用子視圖導入xib。 Xib只是為了顯示圖像。 它具有一個UIImageView和一個UIBarButtonItem。 將圖像導入為子視圖后如何設置圖像?
我試過在子視圖xib的h + m文件中設置方法,但也許我做錯了。 這是我的代碼
-(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'”
據我所知,沒有一個名為setPreviewImage的方法。 您可以使用setImage:設置圖像:但是必須在xib中的UIImageView上而不是在視圖控制器vc上調用它。
@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];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.