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;

}


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值