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

相关文章

Spring Boot 配置文件之类型、加载顺序与最佳实践记录

《SpringBoot配置文件之类型、加载顺序与最佳实践记录》SpringBoot的配置文件是灵活且强大的工具,通过合理的配置管理,可以让应用开发和部署更加高效,无论是简单的属性配置,还是复杂... 目录Spring Boot 配置文件详解一、Spring Boot 配置文件类型1.1 applicatio

C# WinForms存储过程操作数据库的实例讲解

《C#WinForms存储过程操作数据库的实例讲解》:本文主要介绍C#WinForms存储过程操作数据库的实例,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、存储过程基础二、C# 调用流程1. 数据库连接配置2. 执行存储过程(增删改)3. 查询数据三、事务处

springboot security验证码的登录实例

《springbootsecurity验证码的登录实例》:本文主要介绍springbootsecurity验证码的登录实例,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,... 目录前言代码示例引入依赖定义验证码生成器定义获取验证码及认证接口测试获取验证码登录总结前言在spring

tomcat多实例部署的项目实践

《tomcat多实例部署的项目实践》Tomcat多实例是指在一台设备上运行多个Tomcat服务,这些Tomcat相互独立,本文主要介绍了tomcat多实例部署的项目实践,具有一定的参考价值,感兴趣的可... 目录1.创建项目目录,测试文China编程件2js.创建实例的安装目录3.准备实例的配置文件4.编辑实例的

python+opencv处理颜色之将目标颜色转换实例代码

《python+opencv处理颜色之将目标颜色转换实例代码》OpenCV是一个的跨平台计算机视觉库,可以运行在Linux、Windows和MacOS操作系统上,:本文主要介绍python+ope... 目录下面是代码+ 效果 + 解释转HSV: 关于颜色总是要转HSV的掩膜再标注总结 目标:将红色的部分滤

SpringBoot项目启动报错"找不到或无法加载主类"的解决方法

《SpringBoot项目启动报错找不到或无法加载主类的解决方法》在使用IntelliJIDEA开发基于SpringBoot框架的Java程序时,可能会出现找不到或无法加载主类com.example.... 目录一、问题描述二、排查过程三、解决方案一、问题描述在使用 IntelliJ IDEA 开发基于

Spring 中使用反射创建 Bean 实例的几种方式

《Spring中使用反射创建Bean实例的几种方式》文章介绍了在Spring框架中如何使用反射来创建Bean实例,包括使用Class.newInstance()、Constructor.newI... 目录1. 使用 Class.newInstance() (仅限无参构造函数):2. 使用 Construc

MyBatis-Plus中Service接口的lambdaUpdate用法及实例分析

《MyBatis-Plus中Service接口的lambdaUpdate用法及实例分析》本文将详细讲解MyBatis-Plus中的lambdaUpdate用法,并提供丰富的案例来帮助读者更好地理解和应... 目录深入探索MyBATis-Plus中Service接口的lambdaUpdate用法及示例案例背景

MyBatis-Plus中静态工具Db的多种用法及实例分析

《MyBatis-Plus中静态工具Db的多种用法及实例分析》本文将详细讲解MyBatis-Plus中静态工具Db的各种用法,并结合具体案例进行演示和说明,具有很好的参考价值,希望对大家有所帮助,如有... 目录MyBATis-Plus中静态工具Db的多种用法及实例案例背景使用静态工具Db进行数据库操作插入

Android WebView无法加载H5页面的常见问题和解决方法

《AndroidWebView无法加载H5页面的常见问题和解决方法》AndroidWebView是一种视图组件,使得Android应用能够显示网页内容,它基于Chromium,具备现代浏览器的许多功... 目录1. WebView 简介2. 常见问题3. 网络权限设置4. 启用 JavaScript5. D