如果人多的话,我的tableView
卷轴会滞后。最多 20 个单元格运行良好,但高于 - 它在滚动时开始滞后。请建议一个具有更好滚动结果的实现。这是我的做法:
我已经定义了一个自定义UITableViewCell
类。
该单元格有 4 个标签和一个imageView
(每个出口是一个综合属性):
tableView
我在我的 中放置了一个viewController
,并像这样填充它:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CustomCell";
MyCustomCell *cell = (MyCustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"MyCustomCell" owner:self options:nil];
for (id currentObject in topLevelObjects)
if ([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (MyCustomCell *) currentObject;
break;
}
}
[cell.label_descr setText:@"bla-bla-bla"];
[cell.label_date setText:@"bla-bla-bla"];
[cell.label_time setText:@"bla-bla-bla"];
[cell.label_numeric setText:@"bla-bla-bla"];
[cell.image_view setImage:[UIImage imageWithContentsOfFile:@"bla-bla-bla"]];
return cell;
}
如您所见,每个单元格中的文本数量非常少,并且用于该图像的图像UIImageView
约为 25x25 .png 文件。
我tableView
的应该有 300 多个单元格(不要怪我,我有一个“来自地狱的客户”)。
请提出一种使tableView
滚动更流畅,没有(很多)滞后的方法。或者另一种方式来向我的“来自地狱”的客户展示那些“该死的超过 300 个细胞”。
提前300谢谢!
PS:对不起,如果重复,但找到的解决方案根本没有帮助。
编辑:
关于用于 imageView 的图像:
我只使用 2 个不同的图像:
- 一个“复选标记”——交易完成
- 和“待处理” - 正在进行的交易
也许我使用在我的 tableViewCell xib 中定义 2 个 imageView 插座,并且只选择所需的 imageView,而不是每次都设置所需的图像?
找到解决方案,感谢大家,尤其是 iNoob 和 max_。
- 在tableViewCell 的xib 中,我将“checkMark”设置为imageView 的默认图像。
在定义单元格的值时
cellForRowAtIndexPath
,只有在需要时,我才会说:if_I_should_present_a_pending_image:
[cell setPending];
用“待定”图像替换“checkMark”(tableViewCell 类中定义的方法):
- (void)setPending{
self.image_view.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"pending_1.png"],
[UIImage imageNamed:@"pending_2.png"],
[UIImage imageNamed:@"pending_3.png"],
[UIImage imageNamed:@"pending_4.png"],
nil];
self.image_view.animationDuration = 2.0;
self.image_view.animationRepeatCount = 0;
[self.image_view startAnimating];
}
l
在那之后,桌子像魅力一样滚动。再次感谢大家。干杯。