tableviewcell中的归属字符串在单元格出列并重新加载之前不显示粗体文本

Cen*_*n92 6 uitableview ios nsmutableattributedstring

我有一个表视图,其中单元格有一个带有一些属性文本的标签.正确设置了文本cellForRowAtIndexPath.正确设置了文本的颜色,但在单元格出列之前,不会显示粗体属性.

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        MyCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
        Model *model = [self.fetchedResultsController objectAtIndexPath:indexPath];
        cell.tag = indexPath.row;
        [cell updateContentWithModel:model atIndexPath:indexPath];
        return cell;
}


- (void)updateContentWithModel:(Model *)model atIndexPath:(NSIndexPath *)indexPath
{
self.model = model;
[self setTextFromModel];
[self setImageFromModelAtIndexPath:indexPath];
}

- (void) setTextFromModel
{
self.title.text = self.model.header;
self.status.attributedText = [self boldString:self.model.status fontSize:self.status.font.pointSize color:[UIColor redColor]];
}

+(NSMutableAttributedString *)boldString:(NSString *)stringToBold fontSize:(CGFloat)fontSize color:(UIColor *)color
{
NSMutableAttributedString *boldString = [[NSMutableAttributedString alloc] initWithString:stringToBold];
[boldString setAttributes:@{NSForegroundColorAttributeName: color,
                            NSFontAttributeName:[UIFont boldSystemFontOfSize:fontSize]} range:NSMakeRange(0, boldString.length)];
return boldString;
}
Run Code Online (Sandbox Code Playgroud)

以前有没有人经历过这样的事情?

小智 6

由于UIAppearance,我有同样的问题.在设置UILabel属性文本之前,将font\color设置为nil.