TDBadgedCell继续缓存BadgeNumber

时间:2010-02-04 16:22:26

标签: iphone objective-c caching uitableview

对于我正在研究的项目,我正在使用Tim Davies编写的TDBadgedCell。尽管单元格在大多数情况下工作正常,但BadgeNumber仍然会被缓存。我想知道如何解决这个问题。

我的[tableView:cellForRowAtIndexPath]消息如下所示:

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

    Contact *contact = [contactArray objectAtIndex:[indexPath row]];

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

    [cell setBadgeNumber:[[contact unreadMessageCount] intValue]];

    UIImage *statusImage = nil;
    if ([[contact status] isEqualToString:@"online"]) {
            statusImage = [[StatusController sharedInstance] imageForStatus:Online];
    } else if ([[contact status] isEqualToString:@"away"]) {
            statusImage = [[StatusController sharedInstance] imageForStatus:Away];  
 }

    [[cell imageView] setImage:statusImage]; 

    NSString *displayName = [contact displayName];
    [[cell textLabel] setText:displayName];

    NSString *phone = [contact phone];
    [[cell detailTextLabel] setText:phone];

    [cell setBadgeNumber:[[contact unreadMessageCount] intValue]];

    return cell;
}

向上和向下滚动时,文本和图像会正确重绘。然而,badgenumber没有。任何有关如何解决这个问题的建议都会受到欢迎。

1 个答案:

答案 0 :(得分:0)

在设置badgeNumber以强制重绘单元格之后,尝试在单元格上调用“setNeedsDisplay”。