Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 图像显示在UITableViewCell上_Ios_Objective C_Xcode_Uiimageview - Fatal编程技术网

Ios 图像显示在UITableViewCell上

Ios 图像显示在UITableViewCell上,ios,objective-c,xcode,uiimageview,Ios,Objective C,Xcode,Uiimageview,我试图在UITableViewCell中显示图像,我正在使用web服务获取图像名称。下面是我从web服务的响应中得到的信息 "2514466130834f61a9g38d57h0e2cb-25-ProfilePic.PNG", "26144482598634297156heb8c0dafg-26-ProfilePic.PNG", "2714464392629h60253gd4ec8b1f7a-27-ProfilePic.PNG", "2814449113316a7gh5db0e2139c84f-

我试图在UITableViewCell中显示图像,我正在使用web服务获取图像名称。下面是我从web服务的响应中得到的信息

"2514466130834f61a9g38d57h0e2cb-25-ProfilePic.PNG",
"26144482598634297156heb8c0dafg-26-ProfilePic.PNG",
"2714464392629h60253gd4ec8b1f7a-27-ProfilePic.PNG",
"2814449113316a7gh5db0e2139c84f-28-ProfilePic.PNG",
"2914454043856e3519ah0dbf27cg84-29-ProfilePic.PNG"
以上响应以数组格式保存。然后将这些数组对象附加到url上,我需要在UIImageView上显示图像。
请帮助我。

像下面这样准备您的url

// Consider this is your prefix url 
NSString *urlPrefix = @"https://your_url_prefix/"; // like http://stackoverflow.com/

// Consider this is the array you parsed from the web service
NSArray *resourceArray = @[@"2514466130834f61a9g38d57h0e2cb-25-ProfilePic.PNG", @"26144482598634297156heb8c0dafg-26-ProfilePic.PNG", @"2714464392629h60253gd4ec8b1f7a-27-ProfilePic.PNG", @"2814449113316a7gh5db0e2139c84f-28-ProfilePic.PNG", @"2914454043856e3519ah0dbf27cg84-29-ProfilePic.PNG"];
在tableView的数据源方法CellForRowatineXpath中准备资源url

并使用SDWebImage库加载图像,并将其设置为cell imageView,如

注意:SDWebImage库可以从以下位置下载: 在项目中添加此库文件,并按如下方式导入以使用

#import "UIImageView+WebCache.h"

首先下载异步类

然后把你的.m文件

导入AsyncImageView.h


您有返回图像文件名列表的web服务吗?您想下载这些图像并将其显示在表格中吗?这项任务有很多方面。您已经完成了哪些工作,哪些有问题?您是否使用默认的自定义单元格?请分享代码,这样我可以更好地帮助你。。。
[cell.imageView setImageWithURL:resourceURL];
#import "UIImageView+WebCache.h"
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpletableidentifier=@"simpletableidentifier";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:simpletableidentifier];
    if(cell == nil)
    {
        cell.backgroundColor=[UIColor clearColor];
        cell = [[UITableViewCell alloc ]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpletableidentifier];
    } 

   AsyncImageView *Galleryimg = [[AsyncImageView alloc]initWithFrame:CGRectMake(0,0,40,40)];
   Galleryimg.contentMode = UIViewContentModeScaleAspectFill;
   Galleryimg.clipsToBounds=YES;
   Galleryimg.tag=i;
   Galleryimg.imageURL=[NSURL URLWithString:[Yourstring stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
   [scroll addSubview:Galleryimg];
   return cell;
}