有很多方法可以实现这一点,例如以下方法:
- 首先,您需要创建一个
NSMutableArray
在TableView
Delegates和中加载的全局变量DataSaurce
。 - 现在,在您的api调用上,您需要在全局数组中添加That记录。
- 在最后一个单元格或上,
tableview
您可以根据您的API使用下一页URL再次调用它,并在每次调用时重新加载表格 - 您可以使用github上提供的许多ThirdParty库进行加载:
https://github.com/OpenFibers/DragRefreshAndLoadMoreTableDemo
https://github.com/Abizern/PartialTable
https://github.com/robertmryan/UITableView-Bottom-
Refresh
根据您的代码:
在.h类中
#import <UIKit/UIKit.h>@interface ViewController : UIViewController{ NSURL* nextURL; int currentPage;}在.M类中
- (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:theRequestcompletionHandler: ^(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];}


