i'm using a UICollectionView to render a list of contacts, all coming from a contacts table in the DB.
For each item, i am running a query to FMDB that returns one contact, like this:
__block CTVSimpleContact *simpleContact = [CTVSimpleContact new];
[_queue inDatabase:^(FMDatabase *db) {
FMResultSet *result = [_db executeQuery:@"SELECT * FROM contacts "
@"LIMIT 1 OFFSET ?", [NSNumber numberWithInt:index]];
while([result next]) {
[simpleContact setContactId:[result objectForColumnName:@"id"]];
[simpleContact setDisplayName:[result stringForColumn:@"display_name"]];
[simpleContact setEmail:[result stringForColumn:@"email"]];
NSString *photoUri = [result stringForColumn:@"photo_uri_low"];
if(photoUri != nil) {
[simpleContact setPhoto:photoUri];
}
}
}];
return simpleContact;
My problem is that the scrolling is extremely slow and when i profile using the Time Profiler i get that all the time is spent in the [results next] when reading the row from the table.
What would be the next step to optimize this? The scrolling is extremely laggy for around 2k Contacts.
Thanks!