UITableView Photos Show Up Multiple Times from Gra

2019-09-08 09:22发布

问题:

Right now I am making a Facebook Application For iPad. I pulling the wall and putting it into a UITableView. The way I am putting photos into the tableview is like this:

In the requestDidLoad for querying for array of images.

-(void)request:(FBRequest *)request didLoad:(id)result {

 //Determine if result is a array of images
if ([result objectForKey:@"images"] != nil) {
    if ([request.url rangeOfString: @"=images"].location != NSNotFound) {
         realPicsonWall = result;
        NSLog(@"Result Object: %@", [result objectForKey:@"images"]);


    }      
} 

Then in cellForRowAtIndexPath:

  UITableViewCell *cell = [tableView 
                         dequeueReusableCellWithIdentifier:@"messageCell"];
imageCellData *imageCell = [tableView dequeueReusableCellWithIdentifier:@"imageCell"];
//imageCellData is custom cell.
if ([[objectTypes objectAtIndex:indexPath.row] isEqualToString:@"photo"]) {
    //this is a picture


     NSArray *imagesArray = [realPicsonWall objectForKey:@"images"];
    NSDictionary *imageProps = [imagesArray objectAtIndex:3];

    NSLog(@"imageprops source: %@", [imageProps objectForKey:@"source"]);
    [imageCell.imageview setImageWithURL:[NSURL URLWithString:[imageProps objectForKey:@"source"]]];


    [imageCell layoutSubviews];
    return imageCell;


}else if ([[objectTypes objectAtIndex:indexPath.row] isEqualToString:@"video"]) {
    //this is a video
    NSLog(@"Video Called");
     NSDictionary *fromDictionary = [globalWhoPosted objectAtIndex:indexPath.row];
    cell.textLabel.text = @"Videos Are Not Supported";
     cell.detailTextLabel.text = [NSString stringWithFormat:@"Video Posted By: %@", [fromDictionary objectForKey:@"name"]];
    NSLog(@"Video By: %@", [fromDictionary objectForKey:@"name"]);
    return cell;
} 
else {
    NSDictionary *fromDictionary = [globalWhoPosted objectAtIndex:indexPath.row];
    NSString *story = [messages objectAtIndex:indexPath.row];
    cell.textLabel.text = story;
    cell.detailTextLabel.text = [NSString stringWithFormat:@"By: %@", [fromDictionary objectForKey:@"name"]];

    cell.alpha = 1;
    return cell;
}

return cell;
}

In numberOfRows:

{
   return [messages count];
}

There 2 different images in the wall I bring to pull, but It pulls 2 of the same images, so in the tableview I see the same image 2 times, while it is supposed to be 2 diff. images. Any help would very generous. Thanks.

回答1:

Do you have an example of a graphapi url for which this is the case? Probably what I would do is look for the all the images with the same dimensions. This would then lead to the assumption that if more than one image is in the json, rather than just different resolutions, if you grab those with the same resolutions, then you'll be guaranteed to grab those that are unique.