How to implement “Load More Records” in TableView

2019-03-20 19:51发布

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?

3条回答
Lonely孤独者°
2楼-- · 2019-03-20 20:19

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.

查看更多
\"骚年 ilove
3楼-- · 2019-03-20 20:19

@meetpd its not an answer just a suggestion.

You can use core data instead of sqlite. it will satisfy your requirement of fetching 20 records. It will reduce your code base to 40% (as said by Bard Larson in the Advance Iphone App Development). It is easy to use and faster than sqlite. You can check out the sample code like this : enter image description here

hope this will help you a great deal of coding.

查看更多
我命由我不由天
4楼-- · 2019-03-20 20:25

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;
}
查看更多
登录 后发表回答