0

我有一个 TableView,当我单击一个单元格时,它会推送我的类 ImageViewController 并显示一个图像。这很好用。viewDidLoad 方法在这里。

- (void)viewDidLoad
{
    NSLog(@"ImageViewController Load");    
    NSLog(@"Image String: %@",imageString);
    self.view.contentMode=UIViewContentModeCenter;
    UIImage *im = [UIImage imageNamed:imageString];

    if(im == nil){

        NSLog(@"Image is NULL");
    }

    [image setImage:im];
    self.title = @"View Image";
    [super viewDidLoad];
}

imageString 在 .h 文件中被定义为 NSString。我正在使用 StoryBoard 并通过以下方式启动我的 ImageViewController:

ImageViewController *imageViewController = [segue destinationViewController];
    imageViewController.imageString = [[listData objectAtIndex:selectedIndex]objectForKey:@"image"];

在单击 UIWebView 中的链接时尝试查看图像时遇到问题(屏幕为黑色)。基本上这里 UIWebView 包含我的所有内容,我想在单击链接时查看图像。

为此,我使用以下方法:

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{

并使用以下 javascript 启动 ImageViewController

window.location.href="eft://?type=image&path=Google.jpg";

在 shouldStartLoadingWithRequest 方法中,我使用以下命令推送 ImageViewController:

 ImageViewController *imageViewController =[[ImageViewController alloc]init];
        imageViewController.imageString = path;
        [self.navigationController pushViewController:imageViewController animated:YES];

当我执行检查并且路径和类型字段正确但屏幕为黑色时,图像不为空。我没有依赖路径和类型字段,而是在 ImageViewController 中手动设置这些字段(例如 google.jpg),当从 UIWebView 加载控制器时,它仍然显示黑屏。如果我从表格视图中加载它,它会完美运行???

提前致谢

4

1 回答 1

0

我找到了答案,我需要用故事板参考初始化

于 2012-02-15T23:17:07.483 回答