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

相关文章

swiper实例

大家好,我是燐子,今天给大家带来swiper实例   微信小程序中的 swiper 组件是一种用于创建滑动视图的容器组件,常用于实现图片轮播、广告展示等效果。它通过一系列的子组件 swiper-item 来定义滑动视图的每一个页面。 基本用法   以下是一个简单的 swiper 示例代码:   WXML(页面结构) <swiper autoplay="true" interval="3

Java面试题:通过实例说明内连接、左外连接和右外连接的区别

在 SQL 中,连接(JOIN)用于在多个表之间组合行。最常用的连接类型是内连接(INNER JOIN)、左外连接(LEFT OUTER JOIN)和右外连接(RIGHT OUTER JOIN)。它们的主要区别在于它们如何处理表之间的匹配和不匹配行。下面是每种连接的详细说明和示例。 表示例 假设有两个表:Customers 和 Orders。 Customers CustomerIDCus

iOS HTTPS证书不受信任解决办法

之前开发App的时候服务端使用的是自签名的证书,导致iOS开发过程中调用HTTPS接口时,证书不被信任 - (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAu

ABAP怎么把传入的参数刷新到内表里面呢?

1.在执行相关的功能操作之前,优先执行这一段代码,把输入的数据更新入内表里面 DATA: lo_guid TYPE REF TO cl_gui_alv_grid.CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'IMPORTINGe_grid = lo_guid.CALL METHOD lo_guid->check_changed_data.CALL M

加载资源文件失败

背景         自己以前装了一个海康的深度学习算法平台,试用期是一个月,过了一个月之后,因为没有有效注册码或者加密狗的支持了导致无法使用,于是打算卸载掉,在卸载一个软件的时候,无论是使用控制面板还是软件自带的卸载功能,总是卸载不掉,提示“加载资源文件失败”。该软体主要包括以下两部分: 用自带卸载功能卸载的时候分别提示如下:     用控制面板卸载的时候反应很慢,最后也是提示这个

vue同页面多路由懒加载-及可能存在问题的解决方式

先上图,再解释 图一是多路由页面,图二是路由文件。从图一可以看出每个router-view对应的name都不一样。从图二可以看出层路由对应的组件加载方式要跟图一中的name相对应,并且图二的路由层在跟图一对应的页面中要加上components层,多一个s结尾,里面的的方法名就是图一路由的name值,里面还可以照样用懒加载的方式。 页面上其他的路由在路由文件中也跟图二是一样的写法。 附送可能存在

vue子路由回退后刷新页面方式

最近碰到一个小问题,页面中含有 <transition name="router-slid" mode="out-in"><router-view></router-view></transition> 作为子页面加载显示的地方。但是一般正常子路由通过 this.$router.go(-1) 返回到上一层原先的页面中。通过路由历史返回方式原本父页面想更新数据在created 跟mounted

如何实现一台机器上运行多个MySQL实例?

在一台机器上一个MySQL服务器运行多个MySQL实例有什么好处?这里我先入为主给大家介绍这样做至少存在两个好处(看完这篇文章后理解会更透彻): (1)减轻服务器链接负担 (2)为不同的用户提供不同的mysqld服务器的访问权限以方便这些用户进行自我管理。   下面我介绍具体的实现过程: 一、准备工作     台式机一台、Windows系统、MySQL服务器(我安装的版本是MySQL

VS2012加载失败

1、通过命令提示行工具进入VS安装目录下的Common7\IDE 2、执行devenv.exe /setup /resetuserdata /resetsettings 3、重启VS

IOS 数组去重的几种方式

本来只知道NSSet和KeyValues的。今天又新学了几种方式 还有就是和同事学的一种方式 外层循环从0开始遍历,内层从最后一个元素开始遍历 for(int i=0;i<index;i++){  for(int j=index-1;j>i;j-- ){ } }