UITableView卡顿问题处理

1、

1
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;

这个代理方法每次滑动都会调用 建议不要在里面做耗时操作

eg:重新计算高度

1
2
CGSize strSize = [str boundingRectWithSize:CGSizeMake(BHSCREEN_W - 32, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:BH14Font} context:nil].size;
return strSize.height+10;

2、富文本串AttributeString的绘制也很耗时

1
2
3
4
5
6
7
8
9
10
11
12
13
14
NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:str];
[AttributedStr addAttribute:NSFontAttributeName
value:[UIFont systemFontOfSize:16.0]
range:NSMakeRange(5, str.length-5)];
[AttributedStr addAttribute:NSForegroundColorAttributeName
value:[UIColor redColor]
range:NSMakeRange(5, str.length-5)];
_AmountPayableLabel.attributedText = AttributedStr;