Ios 我有一个自定义表,我想显示来自json的图像,但它在所有行中显示相同的图像

Ios 我有一个自定义表,我想显示来自json的图像,但它在所有行中显示相同的图像,ios,json,uitableview,uiimageview,tablecell,Ios,Json,Uitableview,Uiimageview,Tablecell,首先,在接口部分全局创建一个NSMutableArray,并在viewDidLoad方法中初始化它 // delegate method that returns json -(void)repaint:(NSMutableArray *)retrievedData { if (retrievedData.count > 0) { userObj = [retrievedData objectAtIndex:0]; for (use

首先,在接口部分全局创建一个
NSMutableArray
,并在
viewDidLoad
方法中初始化它

 // delegate method that returns json   
-(void)repaint:(NSMutableArray *)retrievedData
{
    if (retrievedData.count > 0)
    {
        userObj = [retrievedData objectAtIndex:0];

        for (userObj in retrievedData)
        {
        NSLog(@"%@is the value",retrievedData);

        url_Img1=@"http://kiascenehai.pk/assets/uploads/event-images/50x50-thumb/";
        url_Img2=userObj.event_dpURL;
        url_Img_FULL = [url_Img1 stringByAppendingPathComponent:url_Img2];

        NSLog(@"Show url_Img_FULL: %@",url_Img_FULL);
            [tableData addObjectsFromArray:retrievedData];
            [table reloadData];
        }

    }
}
//to display data in table:::
[[cell imageView] setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url_Img_FULL]]]];
在此之后,添加
url\u Img\u FULL
内部
arr

NSMutableArray *arr;
cellforrowatinexpath

[arr addObject:url_Img_FULL];


同样在
numberofrowsatindepath
return arr.count.

将其放入for循环[[cell-imageView]setImage:[UIImage-imageWithData:[NSData-dataWithContentsOfURL:[NSURL-URLWithString:url\Img\u FULL]];实际上,直接调用url\u Img\u FULL,它只显示最后一个图像将url\u Img\u FULL添加到一个NSMutableArrayWellcome到StackOverflow。请添加有关您所面临问题的更多详细信息。复制粘贴您的代码不会有帮助
userObj
用于两个范围,无法确定您使用的是哪个
userObj
。yogesh它工作不正常。如果json得到长响应,应用程序将崩溃。由于未捕获的异常“NSInvalidArgumentException”,您是否有其他ideaTerminating应用程序,原因:'-[用户长度]:未识别的选择器发送到实例0xa4ed500'@user3807662它与tableview无关,它与其他内容相关,无法对对象
User
使用
length
。由于未捕获的异常而终止应用程序'NSRangeException[[cell imageView]setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:arr[indexath.row]]];这里显示:线程1 sigbrit
[[cell imageView] setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:arr[indexPath.row]]]]];
[[cell imageView] setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:arr[indexPath.row]]]]];
Use GCD to download some thing like this

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
    dispatch_async(queue, ^(void) {

       //write the code to download image


         }
        dispatch_async(dispatch_get_main_queue(), ^{
            // Capture the indexPath variable, not the cell variable, and use that


            [tableview reloadData];

        });
    });

and cellforrowatindexpath write

if(are.count>0)
{
[[cell imageView] setImage:[UIImage imageWithData:arr[indexPath.row]]]]];
}

return cell;