【问题标题】:IOS 5 Displaying JPEG is blackIOS 5显示JPEG是黑色的
【发布时间】:2012-02-08 16:56:04
【问题描述】:

我有一个 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 加载控制器时,它仍然显示黑屏。如果我从表格视图中加载它,它会完美运行???

提前致谢

【问题讨论】:

    标签: ios5 uiimageview xcode-storyboard


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-20
      • 2012-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-28
      相关资源
      最近更新 更多