美文网首页恩美第二个APP项目
iOS tableview 上拉加载没有更多数据提示

iOS tableview 上拉加载没有更多数据提示

作者: 凉风起君子意如何 | 来源:发表于2017-10-19 15:52 被阅读1780次
效果图

目前采用的是如下方法,暂且先记录下。(如若考虑封装,使用简单方便等,肯定还有其它最优的方法,后续会更新补充)

大致思路

没有更多记录判断逻辑(以下几种情况):

  1. 当后台返回的pagesize小于客户端请求的pagesize
  2. 没有更多数据时,后台当前页pageNow返回0,默认从1开始(这个看自己项目具体后台是如何定的规则)等

再结合mj_footer的隐藏状态,从而刷新tableview

代码处理

接口请求代码做如下处理:

//没有更多数据
        if ((weakself.UnreceiveItems.count < pageSize) || (feed.pageNow == 0 && weakself.UnreceiveItems.count > 0) ) {
            //该toast可以不要
            [MBProgressHUD showError:NoMoreData toView:weakself.view];
            //不自定义footer的情况下,当没有更多数据时 mj_footer显示没有数据相关信息
            [weakself.tbUnReceive.mj_footer endRefreshingWithNoMoreData];
            //隐藏mj_footer,自定义footer,为效果图
            weakself.tbUnReceive.mj_footer.hidden = YES;
        }

tableview datasource and delegate如下处理:

#pragma mark- tableview datasource
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (self.tbUnReceive.mj_footer.hidden && (section == self.UnreceiveItems.count)) {
        //最后一个item
        return 50.0;
    }
    return 0.01;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    if (self.tbUnReceive.mj_footer.hidden && (section == self.UnreceiveItems.count)) {
        UIView *footer = [UIView new];
        UILabel *lb = [[UILabel alloc ]initWithFrame:CGRectMake(0, 10, kScreenWidth- 40 , 20)];
        lb.text = @"----没有更多记录了----";
        lb.textColor = [UIColor lightGrayColor];
        lb.textAlignment = NSTextAlignmentCenter;
        UILabel *lb1 = [[UILabel alloc ]initWithFrame:CGRectMake(0, 0, kScreenWidth- 40 , 20) ];
        lb1.frame = CGRectMake(0, 30, kScreenWidth- 40 , 20);
        lb1.text = @"合力贷提醒您:市场有风险,投资需谨慎";
        lb1.textColor = [UIColor lightGrayColor];
        lb1.textAlignment = NSTextAlignmentCenter;
        [footer addSubview:lb];
        [footer addSubview:lb1];
        return footer;
    }
    return nil;
}

只是一个很简单的小功能, 大咖请绕行哦,不喜勿喷!

相关文章

网友评论

    本文标题:iOS tableview 上拉加载没有更多数据提示

    本文链接:https://www.haomeiwen.com/subject/swguuxtx.html