开发者

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

开发者 https://www.devze.com 2023-02-10 08:49 出处:网络
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.

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 tim开发者_开发技巧e? 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?


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;
}


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.


@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 :

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

hope this will help you a great deal of coding.

0

精彩评论

暂无评论...
验证码 换一张
取 消