There are many way to achieve this like following way:
- First you need to create one global
NSMutableArray
that load in TableView
Delegates and DataSaurce
.
- Now on your api call you need to add That records in global Array.
- On last cell or the
tableview
you can call it again with next page URL based on your API and reload table on each Call
- You can use for loadMore many thirdParty library available on github:
https://github.com/OpenFibers/DragRefreshAndLoadMoreTableDemo
https://github.com/Abizern/PartialTable
https://github.com/robertmryan/UITableView-Bottom-Refresh
Based On your code:
in .h class
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
NSURL* nextURL;
int currentPage;
}
in .M Class
- (void)viewDidLoad {
currentPage = 1;
[self LoadData];
[super viewDidLoad];
}
-(void)LoadData
{
NSURL *theURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://qa.networc.in:1336/api/dispatcher/rideScheduled/:%d",currentPage]];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:20.0f];
//Specify method of request(Get or Post)
[theRequest setHTTPMethod:@"GET"];
//Pass some default parameter(like content-type etc.)
[theRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[theRequest setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue:token forHTTPHeaderField:@"x-access-token"];
NSURLResponse *theResponse = NULL;
NSError *theError = NULL;
NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&theResponse error:&theError];
if (responseData == nil)
{
return;
}
NSDictionary *dataDictionaryResponse = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&theError];
NSLog(@"url to send request= %@",theURL);
NSLog(@"%@",dataDictionaryResponse);
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:theRequest
completionHandler:
^(NSData *data, NSURLResponse *response, NSError *error) {
NSLog(@"Response:%@ %@\n", response, error);
if(error == nil)
{
NSString * text = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog(@"Data = %@",text);
}
currentPage ++;
dictionary = [[NSJSONSerialization JSONObjectWithData:data options:0 error:nil]objectForKey:@"data"];
NSArray *total = [dictionary objectForKey:@"total"];
NSLog(@"latlop %@", total);
[getid addObjectsFromArray:total];
[self updateTable];
}];
[task resume];
}