iOS之MJRefresh下拉刷新和上啦加载更多实例

2024-05-31 10:32

本文主要是介绍iOS之MJRefresh下拉刷新和上啦加载更多实例,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

#define SIZEOFPAGE 15


static NSString *identifier=@"imitateRecordCell";

@interface LYImitateRecordListVC ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)NSMutableArray *imitateRecordArr;//投注历史记录

@property(nonatomic,strong)UITableView *tab;

@property(nonatomic,assign)NSInteger indexPage;

@property(nonatomic,assign)NSInteger maxPage;//最大页数

@property(nonatomic,assign)CGFloat maxCellH;//cell的高度

@end


@implementation LYImitateRecordListVC


-(NSMutableArray *)imitateRecordArr{

    if(_imitateRecordArr==nil){

        _imitateRecordArr=[PublicManagersharedManager].imitateRecordArr;

    }

    return_imitateRecordArr;

}

- (void)viewDidLoad {

    [superviewDidLoad];

    [selfaddbackBtn];

    self.title=@"投注列表";

    self.view.backgroundColor=[UIColorwhiteColor];

    

    __weaktypeof(self) weakSelf=self;

       dispatch_queue_t global_queue =dispatch_get_global_queue(0,0);

    dispatch_async(global_queue, ^{

        [weakSelf getChaseLottoryList];

    });

   

//    [self getChaseLottoryList];//获取投注记过列表数据

     [selfsetTab];

}

//返回按钮

-(void)addbackBtn{

    

    UIButton *bbtn=[[UIButtonalloc]initWithFrame:CGRectMake(0, 0, 60, 30)];

    [bbtn setImage:[UIImageimageNamed:@"icon_navigation_back"]forState:UIControlStateNormal];

    [bbtn addTarget:selfaction:@selector(backBtn)forControlEvents:UIControlEventTouchDown];

    UIBarButtonItem *fixBtn=[[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpacetarget:selfaction:nil];

    fixBtn.width=-30;

    UIBarButtonItem *backbtn=[[UIBarButtonItemalloc]initWithCustomView:bbtn];

    NSArray *btnArr=@[fixBtn,backbtn];

    self.navigationItem.leftBarButtonItems=btnArr;

}

-(void)backBtn{

    [self.navigationControllerpopViewControllerAnimated:YES];

    

}


//获取投注结果列表

-(void)getChaseLottoryList{

    /*

     返回{"status":-100,"msg":"\u5fc5\u98

    接口http://test.ahwofu.com/kaifa/lottery/tzRows

   

    参数 {"page":"1","limit":"15","token":""}

    

     */

    

//    NSDictionary *paramas=@{

//                            @"page":@"1",

//                            @"limit":@"15"

//                            };

     NSDictionary *paramas=@{@"page":@1,@"limit":@SIZEOFPAGE};

    NSString *url=@"http://test.ahwofu.com/kaifa/lottery/tzRows";

 [LYLottoryrequestBlockgetImitaeLottyoryResultWithurl:urlparams:paramas success:^(NSString *msg,id responseObject) {

     if(responseObject){

     NSMutableArray *imitateRecordArr=[NSMutableArrayarrayWithArray:responseObject];

         self.imitateRecordArr=imitateRecordArr;//从数据库拿到的投注记录

    [PublicManagersharedManager].imitateRecordArr=imitateRecordArr;//存储全局

         [self.tabreloadData];/

         NSLog(@"--touzh jieguo liebiao -----%@",imitateRecordArr);

         for (LYImitateRecordListModal *modalin imitateRecordArr) {

             NSLog(@"-投注列表模型---%@---%@",modal.opencode,modal.doubleStr);

         }

     }

 } failure:^(NSString *msg,NSInteger errorCode) {

     

 }];

  

  

    

}


-(void)setTab{

    UITableView *tab=[[UITableViewalloc]initWithFrame:self.view.framestyle:UITableViewStylePlain];

    [self.viewaddSubview:tab];

    self.tab=tab;

    tab.delegate=self;

    tab.dataSource=self;

    tab.separatorStyle=UITableViewCellSeparatorStyleNone;

    UINib *nib=[UINibnibWithNibName:@"ImitateRecordDetailCell"bundle:nil];

    [tab registerNib:nibforCellReuseIdentifier:identifier];

//    [tab registerClass:[UITableViewCell class] forCellReuseIdentifier:identifier];

    tab.showsHorizontalScrollIndicator=NO;

    /********* 列表上下拉刷新 ( MJRefresh框架) ********************/

    self.tab.header = [MJRefreshNormalHeaderheaderWithRefreshingTarget:selfrefreshingAction:@selector(refreshData)];

    self.tab.footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:selfrefreshingAction:@selector(loadMoreData)];

    tab.estimatedRowHeight=300;

    tab.rowHeight=UITableViewAutomaticDimension;

}


//下拉刷新

-(void)refreshData{

    

if( self.maxPage==1){

        [self.mytab.footer endRefreshing];

    self.maxPage=0;//初始化

    }


    self.indexPage=1;

    

    //    NSString *url=@"http://f.apiplus.cn/ah11x5-50.json";

NSString *url=@"http://test.ahwofu.com/kaifa/lottery/tzRows";

    

    //    NSString *page=[NSString stringWithFormat:@"%tu",self.indexPage];

    NSDictionary *params=@{@"page":@1,@"limit":@SIZEOFPAGE};

    [LYLottoryrequestBlock getImitaeLottyoryResultWithurl:urlparams:params success:^(NSString *msg,id responseObject) {

        if(responseObject && [responseObjectcount]>0){

            NSLog(@"--res-04--%@",responseObject);

            self.imitateRecordArr =responseObject;

            [PublicManagersharedManager].imitateRecordArr=self.imitateRecordArr;

            NSLog(@"----im-001-%@",self.imitateRecordArr);

            [self.tab.headerendRefreshing];

            [self.tabreloadData];

            self.maxPage=0;

            if(self.imitateRecordArr &&self.imitateRecordArr.count>0){

                

            }

            

        }else {

            [self.tab.headerendRefreshing];

            self.maxPage=1;

        }

        

    } failure:^(NSString *msg,NSInteger errorCode) {

        [self.tab.headerendRefreshing];

        

        

    }];

    

    

}



//上拉刷新

-(void)loadMoreData{

    NSLog(@"--self.maxpage---%tu",self.maxPage);

    if(self.maxPage){

        [self.tab.footerendRefreshingWithNoMoreData];

        NSLog(@"return");

        return;

    }

    

    

    self.indexPage++;

    NSLog(@"--self,index--%tu",self.indexPage);

    NSString *page=[NSStringstringWithFormat:@"%tu",self.indexPage];

    NSString *sizeofpage=[NSStringstringWithFormat:@"%tu",SIZEOFPAGE];

    if(self.indexPage==1){//吧初始化请求的数据清空,

        [self.imitateRecordArrremoveAllObjects];

        sizeofpage=[NSStringstringWithFormat:@"%tu",SIZEOFPAGE*2];//如果是第一词上啦刷新,请求双倍的数据

    }

    // NSString *url=@"http://f.apiplus.cn/ah11x5-50.json";

    

NSString *url=@"http://test.ahwofu.com/kaifa/lottery/tzRows";

    

    NSDictionary *params=@{@"page":page,@"limit":sizeofpage};

    

    [LYLottoryrequestBlock getImitaeLottyoryResultWithurl:urlparams:params success:^(NSString *msg,id responseObject) {

        if(responseObject && [responseObjectcount]>0){

            NSLog(@"---count---%tu",[responseObjectcount]);

            

            [self.imitateRecordArraddObjectsFromArray:responseObject];

            

            [PublicManagersharedManager].imitateRecordArr=self.imitateRecordArr;

            NSLog(@"----self.rollModal--%@",self.imitateRecordArr);

            [self.tab.footerendRefreshing];

            [self.tabreloadData];

            

            

        }else {

            self.maxPage=1;//如果是1,表示没有更多数据了

            self.indexPage--;

            [self.tab.footerendRefreshingWithNoMoreData];//如果是endRefreshingWithNoMoreData下次再上啦就不调用上啦刷新了;

        }

        

        

    } failure:^(NSString *msg,NSInteger errorCode) {

        

        self.indexPage--;

        [self.tab.footerendRefreshingWithNoMoreData];

        

        

    }];

    

    

}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 1;

}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    NSLog(@"-numcount----%tu-",self.imitateRecordArr.count);

 return self.imitateRecordArr.count;

}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    ImitateRecordDetailCell *cell=[tableViewdequeueReusableCellWithIdentifier:identifier];

    LYImitateRecordListModal *modal=self.imitateRecordArr[indexPath.row];

    NSLog(@"----------%@",modal.opencode);

 CGFloat maxcelH= [cellsetCellWithModal:modal];//设置cell

    self.maxCellH=maxcelH;

//    cell.textLabel.text=modal.expect;

    cell.selectionStyle=UITableViewCellSelectionStyleNone;

    

    return cell;

}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{


    returnself.maxCellH;

}


这篇关于iOS之MJRefresh下拉刷新和上啦加载更多实例的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1017745

相关文章

SpringBoot+RustFS 实现文件切片极速上传的实例代码

《SpringBoot+RustFS实现文件切片极速上传的实例代码》本文介绍利用SpringBoot和RustFS构建高性能文件切片上传系统,实现大文件秒传、断点续传和分片上传等功能,具有一定的参考... 目录一、为什么选择 RustFS + SpringBoot?二、环境准备与部署2.1 安装 RustF

MySQL的配置文件详解及实例代码

《MySQL的配置文件详解及实例代码》MySQL的配置文件是服务器运行的重要组成部分,用于设置服务器操作的各种参数,下面:本文主要介绍MySQL配置文件的相关资料,文中通过代码介绍的非常详细,需要... 目录前言一、配置文件结构1.[mysqld]2.[client]3.[mysql]4.[mysqldum

Java Stream流以及常用方法操作实例

《JavaStream流以及常用方法操作实例》Stream是对Java中集合的一种增强方式,使用它可以将集合的处理过程变得更加简洁、高效和易读,:本文主要介绍JavaStream流以及常用方法... 目录一、Stream流是什么?二、stream的操作2.1、stream流创建2.2、stream的使用2.

SpringBoot加载profile全面解析

《SpringBoot加载profile全面解析》SpringBoot的Profile机制通过多配置文件和注解实现环境隔离,支持开发、测试、生产等不同环境的灵活配置切换,无需修改代码,关键点包括配置文... 目录题目详细答案什么是 Profile配置 Profile使用application-{profil

springboot项目中集成shiro+jwt完整实例代码

《springboot项目中集成shiro+jwt完整实例代码》本文详细介绍如何在项目中集成Shiro和JWT,实现用户登录校验、token携带及接口权限管理,涉及自定义Realm、ModularRe... 目录简介目的需要的jar集成过程1.配置shiro2.创建自定义Realm2.1 LoginReal

Python跨文件实例化、跨文件调用及导入库示例代码

《Python跨文件实例化、跨文件调用及导入库示例代码》在Python开发过程中,经常会遇到需要在一个工程中调用另一个工程的Python文件的情况,:本文主要介绍Python跨文件实例化、跨文件调... 目录1. 核心对比表格(完整汇总)1.1 自定义模块跨文件调用汇总表1.2 第三方库使用汇总表1.3 导

Android Paging 分页加载库使用实践

《AndroidPaging分页加载库使用实践》AndroidPaging库是Jetpack组件的一部分,它提供了一套完整的解决方案来处理大型数据集的分页加载,本文将深入探讨Paging库... 目录前言一、Paging 库概述二、Paging 3 核心组件1. PagingSource2. Pager3.

MySQL多实例管理如何在一台主机上运行多个mysql

《MySQL多实例管理如何在一台主机上运行多个mysql》文章详解了在Linux主机上通过二进制方式安装MySQL多实例的步骤,涵盖端口配置、数据目录准备、初始化与启动流程,以及排错方法,适用于构建读... 目录一、什么是mysql多实例二、二进制方式安装MySQL1.获取二进制代码包2.安装基础依赖3.清

SpringBoot 异常处理/自定义格式校验的问题实例详解

《SpringBoot异常处理/自定义格式校验的问题实例详解》文章探讨SpringBoot中自定义注解校验问题,区分参数级与类级约束触发的异常类型,建议通过@RestControllerAdvice... 目录1. 问题简要描述2. 异常触发1) 参数级别约束2) 类级别约束3. 异常处理1) 字段级别约束

Apache Ignite缓存基本操作实例详解

《ApacheIgnite缓存基本操作实例详解》文章介绍了ApacheIgnite中IgniteCache的基本操作,涵盖缓存获取、动态创建、销毁、原子及条件更新、异步执行,强调线程池注意事项,避免... 目录一、获取缓存实例(Getting an Instance of a Cache)示例代码:二、动态