I test for first time in the real device, and after fixing some obvious performance problems I'm stuck in how do a smoth scrolling.
This is what I do:
- The data is in sqlite
- I have a small array with the header
- I have in each header array the list of Id's from the Db
Ej:
Header A Ids= 1,2 Header B Ids= 3,4
I load lazy the cell & the object to get the data
Barely 10 items at time
- Loading is fast, only scrolling is a issue
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;
}