Reputation: 1
Hai i am new to iOS App Development.In my project i am getting 4000 of response data from web service and i need to display it on tableview But the condition here is I have to display only 30 records initially and once user scroll down I have to load more records.
Upvotes: 0
Views: 1078
Reputation: 1555
You can manage it with following two ways:
1) Manually
Here what you need to do is, You need to take two NSMutableArray
, let say responseArray and tblArray. From that responseArray contains response of your web service and tblArray will manage UITableView
count.
By this you can initially show a set of data, for e.g. 10, so int count = 10
, by adding first 10 record from responseArray to tblArray . When user scroll down you can get 11-20 data from responseArray and add them to tblArray using
for(int i = 10; i < 20; i++)
{
[tblArray addObject:[responseArray objectAtIndex:i]]
}
[<your TableView Name> reloadData];
count += 10;
2) Handel From Server Side
With this option you can easily handle whole the stuff.
For this you only need to pass your current count/Paging value to server and server will response you back accordingly.
For example: initially you don't have any record right now. So you can pass 0 in the web service parameter.
Once you get the response of that you will have 10 records in response. Display them in your UITableView
.
Now when user scroll down you can manage array count here in
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
In the above method you can increase your count value by 1 or you can set it equal to your array count. For now count += 1
or count += <yourArrayName>.count
.
After that you again pass the count value as your web service parameter and you will get next 10 record in your response. Which you need to append to your array by [<yourArrayName> arrayByAddingObjectsFromArray:<your resposeArray>];
.
Using either way you can get your problem solve. But I personally recommend to go with the 2nd option.
Upvotes: 1
Reputation: 529
If you are looking for a third party library to implement Load More, you could try this
https://github.com/samvermette/SVPullToRefresh
Manually you could also use UIScrollViewDelegate
method scrollViewDidEndDecelerating
to keep track of last visible cell, after which you can append more data in your dataSource
.
Upvotes: 0