Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

Murat KAYA
Murat KAYA
10,127 Points

UITableView Pagination JSON

Hi, I have an Json data looks like this.

{
"page": 1,
"results": [
{
"adult": false,
"backdrop_path": "/AsJVim0Hk3KbQPbfjyijfjqmaoZ.jpg",
"id": 194662,
"original_title": "Birdman",
"release_date": "2014-10-17",
"poster_path": "/eOJUEs5cyMFrQuRPQI0glVOVgyo.jpg",
"popularity": 39.4559237723058,
"title": "Birdman",
"video": false,
"vote_average": 7.8,
"vote_count": 570
}
"total_pages": 10667,
"total_results": 213330
}

So I'm trying to make when the user come to the end of the tableview I want to load second page.So What I have to do ?

PS I'am reading first page already. Thanks

Dominic Bryan
Dominic Bryan
14,452 Points

okay I am trying to figure this out but you have a table that displays this information, and you want users who reach the bottom to then find the next page of results, correct?

Murat KAYA
Murat KAYA
10,127 Points

Actually I have a tableview and It's look like http://prntscr.com/6cjte2 .So I'm trying to do if user reach the bottom then I want to get next page.Thats What I'am trying.

Murat KAYA
Murat KAYA
10,127 Points

Actually I used this for detect user is reach the bottom.

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (self.tableView.contentOffset.y >= (self.tableView.contentSize.height -self.tableView.bounds.size.height)) {
        NSLog(@"bottom");

    }
}

But I couldn't implement for loop.Can anybody help me

Dominic Bryan
Dominic Bryan
14,452 Points

yes I see what you are doing and in theory it would be as simple as when the scroll view reaches the bottom (of which you currently print the line "bottom") you want to append or extend your current array of information with page 2, then reload the table.

This is semi inefficient in the sense you a reloading all the table so if you got to page 100 you would be reloading 100 pages, but I believe this is the same way some like infintescroll which is a github project works.

Murat KAYA
Murat KAYA
10,127 Points

So How can I use that. I have to get next page.But I don't have an idea how can I do it ?

Dominic Bryan
Dominic Bryan
14,452 Points

AS I said its hard to do without seeing the code, but just make an IF statement that if the scroll is at the bottom then locate the dictionary that holds page 2 and append/extend to the first page dictionary

That would be my guess, unfortunately I am stuck as far goes as obj-C as I learnt swift first.

Sorry I couldn't be of much help