2010-02-06 28 views
2

这篇文章缓存问题密切相关,我以前的帖子:TDBadgedCell keeps caching the BadgeNumber与TDBadgedCell

的“徽章”从TDBadgedCell保持高速缓存的数量。一个非常简单的例子如下:

- (UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"Cell"; 

    TDBadgedCell *cell = (TDBadgedCell *)[_tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 
     cell = [[TDBadgedCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
     [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; 
    } 

    [cell setBadgeColor:[UIColor blackColor]]; 
    [cell setBadgeNumber:[indexPath row]]; 

    [[cell textLabel] setText:[NSString stringWithFormat:%@"%d", [indexPath row]]]; 

    return cell; 
} 

任何人都有任何线索为什么会发生这种情况? textLabel和detailTextLabel不会缓存数据。任何额外的信息也会受到欢迎,因为我似乎在UITableViewCells中缓存图形有很多问题。任何最佳实践或其他有用的信息将是最受欢迎的。

回答

1

好吧,我想出了这一个。显然,我不应该使用默认代码来初始化使用TDBadgedCell时的单元格。下面的代码:

TDBadgedCell *cell = (TDBadgedCell *)[_tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell == nil) { 
    cell = [[TDBadgedCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
    [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; 
} 

需要更换成这样:

TDBadgedCell *cell = [[[TDBadgedCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 

我想知道,如果这是在内存使用和这样的条款干净,但它会做至少现在。

0

我认为这是在2013年3月22日提交的承诺2d255f075fe53ad10afe8eb65666207a8f2c65d0中修复的。在我的情况下,最初似乎在大部分时间都解决了这个问题,但偶尔也会看到缓存徽章。然后我意识到你可以通过使用两个不同的单元来一劳永逸地解决这个问题:当你需要一个合格的单元格时,将一个TDBadgedCell出列,并且当你不需要一个徽章时,将一个普通的UITableViewCell出列。