【问题标题】:UITableView Photos Show Up Multiple Times from Graph APIUITableView 照片从 Graph API 显示多次
【发布时间】:2012-05-29 20:29:54
【问题描述】:

现在我正在为 iPad 制作 Facebook 应用程序。我拉墙并将其放入 UITableView。我将照片放入 tableview 的方式是这样的:

在 requestDidLoad 中用于查询图像数组。

-(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"]);


    }      
} 

然后在 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];
}

墙上有 2 个不同的图像我要拉,但它会拉 2 个相同的图像,所以在 tableview 中我看到相同的图像 2 次,而它应该是 2 差异。图片。任何帮助都会非常慷慨。谢谢。

【问题讨论】:

  • 你能发布整个 cellForRowAtIndexPath 方法吗? objectTypes 在哪里定义和分配?
  • @obuseme 整个cellForRowAtIndexPath 已发布

标签: ios facebook-graph-api uitableview sdwebimage


【解决方案1】:

您是否有一个属于这种情况的 graphapi url 示例?可能我会做的是寻找所有具有相同尺寸的图像。这将导致假设如果 json 中有多个图像,而不仅仅是不同的分辨率,如果您抓取具有相同分辨率的图像,那么您将保证抓取那些唯一的图像。

【讨论】:

  • 这不起作用,因为正如上面所说,索引 3 只是它返回图像的尺寸。
  • 我已经添加了 nonumberofrowsCode
  • json 模式表明我的响应是准确的
  • json 模式显示 [realPicsonWall objectForKey:@"images"] 返回一个图像对象数组。每个对象代表一个不同的图像。如果不是这种情况,请粘贴示例 json 的副本
  • 返回同一张图片的多种尺寸。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-10-12
  • 1970-01-01
  • 2011-11-10
  • 2011-08-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多