[英]Poor scrolling performance in UITableView with cell subviews.
我有一个包含许多行的UITableView。 每行都有一个UIView,我在cellForRowAtIndexPath中编辑。 我的问题是这在iPod touch上非常落后。 我不确定为什么会这样,因为iPod应该能够同时在屏幕上拍摄超过11个UIViews? 有谁知道为什么会这样?
编辑 - 这是代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UIView *colorView = (UIView *)[cell viewWithTag:1];
UILabel *label = (UILabel *)[cell viewWithTag:2];
colorView.layer.cornerRadius = 10;
colorView.layer.borderColor = [UIColor blackColor].CGColor;
colorView.layer.borderWidth = 2.0f;
colorView.layer.masksToBounds = YES;
switch (indexPath.row) {
case 0:
label.text = @"White";
colorView.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
break;
case 1:
label.text = @"Olive";
colorView.backgroundColor = [UIColor colorWithRed:0.814 green:0.551 blue:0.119 alpha:1];
break;
case 2:
label.text = @"Dark Blue";
colorView.backgroundColor = [UIColor colorWithRed:0.036 green:0 blue:1 alpha:1];
break;
case 3:
label.text = @"Dark Green";
colorView.backgroundColor = [UIColor colorWithRed:0 green:0.387 blue:0.006 alpha:1];
break;
case 4:
label.text = @"Orange";
colorView.backgroundColor = [UIColor colorWithRed:1 green:0.500 blue:0 alpha:1];
break;
case 5:
label.text = @"Dark Brown";
colorView.backgroundColor = [UIColor colorWithRed:0.399 green:0.269 blue:0.137 alpha:1];
break;
case 6:
label.text = @"Dark Red";
colorView.backgroundColor = [UIColor colorWithRed:0.530 green:0.017 blue:0 alpha:1];
break;
case 7:
label.text = @"Maroon";
colorView.backgroundColor = [UIColor colorWithRed:0.502 green:0 blue:0.251 alpha:1];
break;
case 8:
label.text = @"Yellow";
colorView.backgroundColor = [UIColor colorWithRed:0.865 green:0.864 blue:0.002 alpha:1];
break;
case 9:
label.text = @"Purple";
colorView.backgroundColor = [UIColor colorWithRed:0.460 green:0 blue:0.865 alpha:1];
break;
default:
label.text = @"";
colorView.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
break;
}
return cell;
}
谢谢
你可以在这里做一些事情。
打开石英调试(使用仪器在设备上,或者最近,在模拟器中)。 颜色混合层 - 你应该看到绿色。 如果不这样做,请确保新视图标记为不透明。 滚动透明视图需要很多性能。
如果这没有帮助,请使用仪器中的时间分析器进行分析。 花在哪里? 例如,您是否应该缓存用于背景的颜色?
理想情况下,您的图层属性只能设置一次。 自定义单元子类中的awakeFromNib是一个很好的地方。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.