Search code examples
jsonuitableviewios7custom-cell

i just want to print several images that fetched from a method named repaint and to all these images seperatly on custom cells of table in ios


// custom delegate that takes value in retrieved data array ::
-(void)repaint:(NSMutableArray *)retrievedData
{
    if (retrievedData.count > 0)
    {
        userObj = [retrievedData objectAtIndex:0];

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

       [tableData addObjectsFromArray:retrievedData];
        [table reloadData];
      }
}

This code is printing a single image several times.

[[cell imageView] setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL       URLWithString:url_Img_FULL]]]];

Solution

  • It's probably this line, where you always take the first object from the array:

    userObj = [retrievedData objectAtIndex:0];
    //                                     ^
    

    Use Fast Enumeration instead:

    -(void)repaint:(NSMutableArray *)retrievedData
    {
        for (WhateverType *userObj in 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];
    
           [tableData addObjectsFromArray:retrievedData];
            [table reloadData];
          }
    }
    

    Note: none of the variables in that method should be an instance variable, other than tableData and table. Also that URL manipulation code looks dodgy, but that's a different story...