iOS开发tableview二级联动的细节实现中注意的细节总结

本文介绍了一种通过比较请求参数来判断并刷新UITableView的方法,解决了在网络速度慢时数据加载不及时导致的显示问题。同时,针对上拉加载更多时footer状态显示不一致的问题也给出了具体的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先说网络慢带来的数据显示问题

可以通过判断请求参数是否一致来刷新tableview。

SJBCategaryModel * categaryModel = self.categarys[CategarySelectRow];

 

    NSMutableDictionary * params = [NSMutableDictionary dictionary];

    categaryModel.currentPage = 1;

    params[@"a"] = @"list";

    params[@"c"] = @"subscribe";

    params[@"category_id"] = @(categaryModel.id);

    params[@"page"] = @(categaryModel.currentPage);

    self.params = params;

  

        [self.manager GET:Main_URL parameters:params progress:^(NSProgress * _Nonnull downloadProgress) {

            

        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

            if (self.params != params) return;

            [categaryModel.userArrM removeAllObjects];

          

            for (int i=0; i<[responseObject[@"list"] count]; i++) {

                SJBUserModel * model = [[SJBUserModel alloc] init];

                [model setValuesForKeysWithDictionary:responseObject[@"list"][i]];

                [categaryModel.userArrM addObject:model];

            }

            categaryModel.total = [responseObject[@"total"] integerValue];

            

            [self.userTableView reloadData];

            [self.userTableView.mj_header endRefreshing];

            [self checkTableFooterState];

         

        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

            [self.userTableView.mj_header endRefreshing];

        }];

 上啦加载时,footer显示不一致的问题

   

    if (!self.categarys.count) {

        return;

    }

  

    SJBCategaryModel * categaryModel = self.categarys[CategarySelectRow];

    

    self.userTableView.mj_footer.hidden = (categaryModel.userArrM.count == 0);

 

    if (categaryModel.userArrM.count == categaryModel.total) {

        

        [self.userTableView.mj_footer endRefreshingWithNoMoreData];

    }else{

        [self.userTableView.mj_footer endRefreshing];

    }

 如果请求的数据的数量与总量相等就显示没有更多的数据,若小于总量就显示点击或上拉加载更多的数据。

转载于:https://www.cnblogs.com/jianbo-su/p/5624167.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值