如何解决UITableView中的慢速滚动问题 [英] How to solve slow scrolling in UITableView
本文介绍了如何解决UITableView中的慢速滚动问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在第一次在真实设备上进行测试,在解决了一些明显的性能问题之后,我一直坚持如何平滑滚动。
I'm testing for the first time on a real device, and after fixing some obvious performance problems, I'm stuck on how do smooth scrolling.
这个是我做的:
- 数据在sqlite中
- 我有一个小数组标题
- 我在每个标题数组中都有来自Db的Id列表
例如
标题A
Ids = 1,2;
标题B
Ids = 3,4
Header A Ids= 1,2; Header B Ids= 3,4
- 我懒惰加载单元格&获取数据的对象
- 一次只加载10个项目
- 加载速度快,只滚动是个问题
这是加载单元格的代码:
This is the code on the loading of the cell:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ProductCell";
ProductCell *cell = (ProductCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ProductCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
// Set up the cell...
Product *p = [self locateRecord:indexPath];
cell.nameLabel.text = [p.name capitalizedString];
cell.codeLabel.text = p.ref;
if ([self.selectedProducts objectForKey:[NSNumber numberWithInt:p.Id]]) {
OrderDetail *d = [self findDetail:p];
cell.qty.text = [NSString stringWithFormat:@"%ld",[d.qty integerValue]];
}
return cell;
}
- (id) locateRecord:(NSIndexPath *)indexPath {
NSNumber *theId;
NSUInteger pos = [indexPath row];
id o;
if (self.results) {
theId = [self.results objectAtIndex:pos];
} else {
NSString *key = [[self.index objectAtIndex:[indexPath section]] objectAtIndex:0];
NSArray *data = [self.cache objectForKey:key];
theId = [data objectAtIndex:pos];
}
Db *db= [Db currentDb];
o = [db loadById:[self returnItemClass] theId:[theId intValue]];
return o;
}
推荐答案
- 预加载数据
- 自己画画
- Preload the data
- Do your own drawing
这篇关于如何解决UITableView中的慢速滚动问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文