2011-06-10 34 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對財產!

我希望這可以幫助別人!