0

I have a table view controller that is fetching objects from a database hosted by parse.com. At the moment, I have the view controller fetch all the objects in the database for storage in an array. Right now, there are 100 objects in the database, and what I would like to do, is have the table view controller fetch 20 of those objects and display them, then have it fetch and display 20 more when the table scrolls to the bottom.

Here is my init method:

- (id)initWithStyle:(UITableViewStyle)style{
    self = [super initWithStyle:style];
    if (self) {
        //create the array, set the table view size, then populate it. 
        listings = [[NSMutableArray alloc] init];
        [self populateArrayWithListings]; 
    }
    return self;
}

[self populateArrayWithListings]; simply fills the array listings with the 100 objects in the database. I have this method to detect when the table view controller is scrolled to at the bottom:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView.contentOffset.y + scrollView.bounds.size.height > scrollView.contentSize.height * 0.9) {

    }
}

Question is, what should I put inside those brackets to have it fetch the next 20 objects in the database?

10
  • If you're using UITableView, it will long only the cells that are about to appear in the screen and not all of them. You don't need to worry about it. It does the memory management for you. Just make sure you're creating the cell properly. Does that respond to your question? Commented Aug 23, 2013 at 0:29
  • Can you also post your query code? Are you using limit and skip (from the Query Contraints section in the Parse iOS Docs? Commented Aug 23, 2013 at 0:30
  • That is a helpful answer yes, but I think it would still be more efficient for me to query incrementally, as the database will not always have 100 objects. I am expecting this number to increase by a lot in the long run, and querying for 1000+ objects might take a while. Commented Aug 23, 2013 at 0:31
  • @Will I have taken a look at limit and was wondering how I would be able to implement it. The only thing I could think of was to increase the limit when needed and "re-query" the objects, but that seemed inefficient to me. Is it? Commented Aug 23, 2013 at 0:33
  • 1
    There is a video tutorial at parse.com/tutorials/parse-query-table that shows a way to do this out of the box using one of parse.com's own classes. Unless you have a reason not to, I'd recommend using PFQueryTableViewController. Commented Aug 23, 2013 at 0:36

1 Answer 1

2

I did the same thing what you needed.

FQuery *postQuery = [PFQuery queryWithClassName:@"Challenge"];
[postQuery addDescendingOrder:@"createdAt"];
[postQuery includeKey:@"userId"];

[postQuery setSkip:[mutArrPagingResponce count]];
[postQuery setLimit:20];

// Declare this array gloabally or keep it in another array
NSMutableArray *mutArrPagingResponce = [[postQuery findObjects] mutableCopy];

This will work as you are trying to achieve. Let me know if anything else required.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.