我是第一次在真实设备上进行测试,并且在解决了一些明显的性能问题后,我仍然坚持如何平滑滚动。

这是我的工作:

  • 数据以sqlite格式显示
  • 我有一个带有标题
  • 的小数组
  • 我在每个 header 数组中都有来自Db
  • 的ID列表

    例如

    header A
    Ids = 1,2;
    header B
    编号= 3,4
  • 我懒加载单元格和对象以获取数据
  • 一次仅加载10个项目
  • 加载速度很快,仅滚动是一个问题

  • 这是关于单元格加载的代码:
    - (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;
    }
    

    最佳答案

  • 预加载数据
  • Do your own drawing
  • 关于iphone - 如何解决UITableView中的缓慢滚动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/695814/

    10-14 20:25
    查看更多