为什么在目标C的cellforRowAtIndexPath中未显示图像

木竹

我是iOS的新手,并且遇到有关在Web Service的``图像视图''中显示图像的问题。我正在使用类似这样的代码

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *STI=@"STI";
    NewsTableViewCell *cell = (NewsTableViewCell *)[tableView dequeueReusableHeaderFooterViewWithIdentifier:STI];
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"NewsTableViewCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
        cell.accessoryType=UITableViewCellAccessoryNone;
    }

    NSString *strImgURLAsString = [NewsImageArray objectAtIndex:indexPath.row];
    [strImgURLAsString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *imgURL = [NSURL URLWithString:strImgURLAsString];
    [NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:imgURL] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if (!connectionError) {
            img = [[UIImage alloc] initWithData:data];
            if (img==nil) {
               // img=[UIImage imageNamed:@"userimage.png"];
            }
            cell.newsimage.image=img;

            // pass the img to your imageview
        }else{
            NSLog(@"%@",connectionError);
        }
    }];

    cell.Headlbl.text=[NSString stringWithFormat:@"%@",[headarray objectAtIndex:indexPath.row]];

    NSString *aux = [shortnamearray objectAtIndex:indexPath.row];
    NSString * htmlString = @"<html><body>";
    NSString *htmlString2=@"</body></html>";
    NSString * NewString=[NSString stringWithFormat:@"%@%@%@",htmlString,aux,htmlString2];

    NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[NewString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];

    cell.bodylbl.attributedText=attrStr;
    cell.bodylbl.textAlignment=NSTextAlignmentCenter;
    cell.bodylbl.textColor=[UIColor whiteColor];
    [cell.bodylbl setFont:[UIFont fontWithName:@"Arial" size:16]];

    cell.backgroundColor = cell.contentView.backgroundColor;


   // cell.bodylbl.text=[NSString stringWithFormat:@"%@",[shortnamearray objectAtIndex:indexPath.row]];
 //   cell.randrid.text=[NSString stringWithFormat:@"%@",[idarray objectAtIndex:indexPath.row]];
    return cell;

}

图像路径- http://qaec.teams.in.net/UploadedFiles/Tommy舍费尔,他在杀害作用,为他所服务的18 year.png

http://qaec.teams.in.net/UploadedFiles/Tommy%20Schaefer,%20of%20his%20role%20in%20the%20slaying,%20for%20which%20he%20is%20serving%2018%20year.png

在此处输入图片说明 当图像不包含任何间隙时,它显示图像,但是当图像不包含任何间隙时,它不显示图像。如何解决此问题。在此先感谢!

基因密码

不需要使用任何其他库等。您的代码在此行上是错误的:

[strImgURLAsString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

看看这有什么用吗?没有什么。您应该将变量strImgURLAsString分配给它,然后它应该可以工作:

 strImgURLAsString = [strImgURLAsString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

为什么我的图像未显示在Tkinter画布中

来自分类Dev

cellforrowatindexpath 如何在目标 c 中工作

来自分类Dev

为什么图像上传未显示图像预览文本?

来自分类Dev

为什么?单元测试覆盖率中显示的类即使未添加到测试目标中

来自分类Dev

为什么在iOS中将tableview样式分组后,目标c中的标题部分的视图无法正确显示,目标c

来自分类Dev

为什么我在.md中嵌入的图像未显示在Github上

来自分类Dev

为什么在Heroku上部署的Rails应用程序中未显示图像?

来自分类Dev

.css 中定义的类背景未显示在网页上。无法识别图像路径。为什么?

来自分类Dev

为什么此 PDF 中的纯青色图像未显示为纯青色?

来自分类Dev

为什么标签未显示在图表中

来自分类Dev

为什么数据未显示在nextjs中?

来自分类Dev

vuforia图像目标为白色(未显示我的图像目标)

来自分类Dev

为什么const在typeid()。name()中未显示在输出中,C ++

来自分类Dev

在cellForRowAtIndexPath中自动调用的目标

来自分类Dev

Obj-C:为什么我的图像不能显示在NSImageView中?

来自分类Dev

在终端中创建的别名未显示在tmux中。为什么?

来自分类Dev

为什么使用Retrofit Multipart上传图像时服务器上未显示图像?

来自分类Dev

为什么不显示图像?

来自分类Dev

为什么 tmux 会话未显示在 who 命令中?

来自分类Dev

为什么Windows中未显示Acrobat PDF标签?

来自分类Dev

为什么MD RAID重新同步未显示在“ iotop”中?

来自分类Dev

为什么以太网设备未显示在“ / dev”中?

来自分类Dev

为什么图片未显示在gmail的html邮件中?

来自分类Dev

Web API 中未显示操作方法,为什么?

来自分类Dev

为什么Django模板中未显示用户列表?

来自分类Dev

为什么使用getter在vue js中未显示counter?

来自分类Dev

为什么在DRF响应中未显示“ url”

来自分类Dev

为什么列表视图未显示在片段中?

来自分类Dev

为什么我不能在 html 中全屏显示图像?

Related 相关文章

  1. 1

    为什么我的图像未显示在Tkinter画布中

  2. 2

    cellforrowatindexpath 如何在目标 c 中工作

  3. 3

    为什么图像上传未显示图像预览文本?

  4. 4

    为什么?单元测试覆盖率中显示的类即使未添加到测试目标中

  5. 5

    为什么在iOS中将tableview样式分组后,目标c中的标题部分的视图无法正确显示,目标c

  6. 6

    为什么我在.md中嵌入的图像未显示在Github上

  7. 7

    为什么在Heroku上部署的Rails应用程序中未显示图像?

  8. 8

    .css 中定义的类背景未显示在网页上。无法识别图像路径。为什么?

  9. 9

    为什么此 PDF 中的纯青色图像未显示为纯青色?

  10. 10

    为什么标签未显示在图表中

  11. 11

    为什么数据未显示在nextjs中?

  12. 12

    vuforia图像目标为白色(未显示我的图像目标)

  13. 13

    为什么const在typeid()。name()中未显示在输出中,C ++

  14. 14

    在cellForRowAtIndexPath中自动调用的目标

  15. 15

    Obj-C:为什么我的图像不能显示在NSImageView中?

  16. 16

    在终端中创建的别名未显示在tmux中。为什么?

  17. 17

    为什么使用Retrofit Multipart上传图像时服务器上未显示图像?

  18. 18

    为什么不显示图像?

  19. 19

    为什么 tmux 会话未显示在 who 命令中?

  20. 20

    为什么Windows中未显示Acrobat PDF标签?

  21. 21

    为什么MD RAID重新同步未显示在“ iotop”中?

  22. 22

    为什么以太网设备未显示在“ / dev”中?

  23. 23

    为什么图片未显示在gmail的html邮件中?

  24. 24

    Web API 中未显示操作方法,为什么?

  25. 25

    为什么Django模板中未显示用户列表?

  26. 26

    为什么使用getter在vue js中未显示counter?

  27. 27

    为什么在DRF响应中未显示“ url”

  28. 28

    为什么列表视图未显示在片段中?

  29. 29

    为什么我不能在 html 中全屏显示图像?

热门标签

归档