2011-06-10 52 views
1

我与SDWebImage和UITableView的工作SDWebImage和UITableViewCell的

- (UITableViewCell *)tableView:(UITableView *)the_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

    NSString *MyIdentifier = [NSString stringWithFormat:@"MyIdentifier"]; 
    NSDictionary *info = [tableData objectAtIndex:indexPath.row]; 

    UITableViewCell *cell = [the_tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyIdentifier] autorelease]; 
     if(!addImage) [addImage release]; 
     addImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"placeholder.png"]]; 
     [addImage setFrame:CGRectMake(7, 10, 50, 50)]; 
     [cell setIndentationLevel:6]; 
     [cell.contentView addSubview:addImage]; 
    } 

    if(info != NULL) { 
     cell.textLabel.text = [info objectForKey:@"title"]; 
     cell.detailTextLabel.text = [NSString stringWithFormat:@"Version: %@",[info objectForKey:@"version"]]; 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

     NSString *imageURL = [NSString stringWithFormat:@"%@",[info objectForKey:@"imageURL"]]; 
     [addImage setImageWithURL:[NSURL URLWithString:imageURL] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];   
    } 
    return cell; 
} 

它第6个结果的伟大工程(能适合于眼前的金额来看)

但正如我向下滚动列表中,它似乎只是重复使用前6个单元格中的图像,而在某些单元格上,图像会根据它们在屏幕上的位置而变化。另外,如果我调用reloadData,则来自先前UITableCells的图像将保留在屏幕上!

我在这里做错了什么?我遵循github上的示例代码..

谢谢!

回答

0

(可以通过在一个问题编辑OP回答搬到这里为社区维基答案见Question with no answers, but issue solved in the comments (or extended in chat)

的OP写道:

好了,我发现这个问题。

对于那里的其他人有同样的问题,这是你做错了的地方!

通知我如何添加图片到子视图同时创造一个细胞:

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyIdentifier] autorelease]; 
addImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"placeholder.png"]]; 
[addImage setFrame:CGRectMake(7, 10, 50, 50)]; 
[cell.contentView addSubview:addImage]; 

那么,什么SDWebImage试图做的是不断更新addImage变量,它不是一个我的细胞类的属性。

所以,我做了什么来解决这个问题是创建自己的UITableViewCell子类,即init的一个ImageView和我SDWebImagesetImage对财产!

我希望这可以帮助别人!