Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement "Load More Records" in TableView in iPhone SDK?

I have 10,000 rows in database table. I have a view which is suppose to list all these rows in a tableview. But loading all in one shot takes ages to appear in tableview.

How can we use "Load More Records" feature which will fetch 20 records at a time? If user wants to view more entries, they can click "Load More Records" button and it will show next 20 records.

Will have to modify my select statement? What other changes do I have to do to achieve this?

like image 429
meetpd Avatar asked Feb 11 '11 05:02

meetpd


2 Answers

UITableView reuses its cells. This means you can dynamically access your database when cellForRowAtIndexPath: is called- you don't need to load all 10000 elements at once, nor should you. I hope this helps, and that I'm not misunderstanding your question.

This is pretty basic UITableView stuff, but it should get you started. Sorry I don't know much about either Core Data or SQLite.

- (UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
            cell = [[[NSBundle mainBundle] loadNibNamed:@"CustomCell-iPad" owner:self options:nil] lastObject];
        }
        else{
            cell = [[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil] lastObject];
        }
    }


// Do stuff, load database values, etc

    return cell;
}
like image 87
jakev Avatar answered Oct 26 '22 20:10

jakev


Thanks everyone for your inputs. But I was able to implement this using below link:

http://useyourloaf.com/blog/2010/10/2/dynamically-loading-new-rows-into-a-table.html

Hope this is useful to all.

like image 44
meetpd Avatar answered Oct 26 '22 20:10

meetpd