NSAttributedString 在 tableViewCell 中滚动不流畅(disappearing/reappearing)
NSAttributedString not scrolling smoothly (disappearing/reappearing) in tableViewCell
我有一个表格视图单元格,其中有一个按钮。在这个按钮中,我显示了一个动态的属性文本。但是,这有效,当我上下滚动时,文本消失并在四分之一秒后出现,而且非常明显,尤其是在快速滚动时。
调试时,我注意到如果我注释掉行 attString = [[NSMutableAttributed...
直到最后一个 [attString appendAttributedString:[[...
方法(在我的评论下方),并将 profileIDButton
的标题设置为 @"test"
,滚动时没有问题。我认为 attString
的 allocation/initialization 导致了滚动问题。我如何摆脱这种消失和出现四分之一秒后的行为? cellForRowAtIndexPath
?
中没有 allocating/initializing 内存的情况下,有什么方法可以创建属性字符串并附加到它?
//Within the cellForRowAtIndexPath method:
// HERE IS WHERE I BELIEVE IS THE CAUSE OF TEXT DISAPPEARING DUE TO MEMORY ALLOCATION.
attString = [[NSMutableAttributedString alloc] init];
[attString appendAttributedString:[[NSAttributedString alloc] initWithString:@"@" attributes:dict1]];
[attString appendAttributedString:[[NSAttributedString alloc] initWithString:senderName attributes:dict1]];
[attString appendAttributedString:[[NSAttributedString alloc] initWithString:@" posted " attributes:dict2]];
[attString appendAttributedString:[[NSAttributedString alloc] initWithString:recepientName attributes:dict2]];
[attString appendAttributedString:[[NSAttributedString alloc] initWithString:@"." attributes:dict2]];
[cell.profileIDButton setAttributedTitle:attString forState:UIControlStateNormal];
顶部单元格在向上滚动时显示这种刷新行为
将按钮类型设置为 'UIButtonTypeCustom' 也许可行。
我有一个表格视图单元格,其中有一个按钮。在这个按钮中,我显示了一个动态的属性文本。但是,这有效,当我上下滚动时,文本消失并在四分之一秒后出现,而且非常明显,尤其是在快速滚动时。
调试时,我注意到如果我注释掉行 attString = [[NSMutableAttributed...
直到最后一个 [attString appendAttributedString:[[...
方法(在我的评论下方),并将 profileIDButton
的标题设置为 @"test"
,滚动时没有问题。我认为 attString
的 allocation/initialization 导致了滚动问题。我如何摆脱这种消失和出现四分之一秒后的行为? cellForRowAtIndexPath
?
//Within the cellForRowAtIndexPath method:
// HERE IS WHERE I BELIEVE IS THE CAUSE OF TEXT DISAPPEARING DUE TO MEMORY ALLOCATION.
attString = [[NSMutableAttributedString alloc] init];
[attString appendAttributedString:[[NSAttributedString alloc] initWithString:@"@" attributes:dict1]];
[attString appendAttributedString:[[NSAttributedString alloc] initWithString:senderName attributes:dict1]];
[attString appendAttributedString:[[NSAttributedString alloc] initWithString:@" posted " attributes:dict2]];
[attString appendAttributedString:[[NSAttributedString alloc] initWithString:recepientName attributes:dict2]];
[attString appendAttributedString:[[NSAttributedString alloc] initWithString:@"." attributes:dict2]];
[cell.profileIDButton setAttributedTitle:attString forState:UIControlStateNormal];
顶部单元格在向上滚动时显示这种刷新行为
将按钮类型设置为 'UIButtonTypeCustom' 也许可行。