本文介绍了TDBadgedCell继续缓存BadgeNumber的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我正在从事的项目,我正在使用Tim Davies编写的TDBadgedCell。虽然该单元格在大多数情况下都可以正常工作,但BadgeNumber一直在被缓存。我想知道如何解决此问题。

For a project I'm working on I'm using the TDBadgedCell as written by Tim Davies. While the cell works fine for the most part, the BadgeNumber keeps getting cached. I'm wondering how I can fix this.

我的[tableView:cellForRowAtIndexPath]消息看起来像这样:

My [tableView:cellForRowAtIndexPath] message looks like this:

- (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;
}

当我上下滚动时,文本和图像会正确重绘。徽章编号却没有。任何有关如何解决此问题的建议都将受到欢迎。

The text and image gets redrawn correctly when I scroll up and down. The badgenumber doesn't however. Any suggestions on how to fix this would be welcome.

推荐答案

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

Try calling "setNeedsDisplay" on the cell after you've set the badgeNumber to force the cell to redraw.

这篇关于TDBadgedCell继续缓存BadgeNumber的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 13:16