栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在UITableView中添加分页?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在UITableView中添加分页?

有很多方法可以实现这一点,例如以下方法:

  • 首先,您需要创建一个
    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];}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/616849.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号