MJRefresh使用教程

1、自定义刷新标签

//下拉刷新
MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
    [weakSelf.tableView.mj_header endRefreshing];//结束刷新
    weakSelf.viewModel.browingHistoryQuery.pageNo = 1;
    [weakSelf getBrosingHistoryData];
}];
[header setTitle:@"下拉刷新" forState: MJRefreshStateIdle];
[header setTitle:@"释放更新数据" forState:MJRefreshStatePulling];
[header setTitle:@"Loading..." forState:MJRefreshStateRefreshing];
header.lastUpdatedTimeLabel.hidden = YES;
// 设置颜色
header.stateLabel.textColor = [UIColor redColor];
self.tableView.mj_header = header;
//上拉加载更多
MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
    [weakSelf.tableView.mj_footer endRefreshing];//结束刷新
    weakSelf.viewModel.browingHistoryQuery.pageNo += 1;
    [weakSelf getBrosingHistoryData];
}];
[footer setTitle:@"上拉刷新" forState:MJRefreshStateIdle];
[footer setTitle:@"加载更多" forState:MJRefreshStatePulling];
[footer setTitle:@"Loading..." forState:MJRefreshStateRefreshing];
self.tableView.mj_footer = footer;

2、停止、重启上拉刷新
设置state
mj_footer.state = MJRefreshStateNoMoreData;

weakSelf.viewModel.browingHistoryQuery.pageNo += 1;//获取到数据后才增1
if (isNoMoreData) {
    weakSelf.tableView.tableFooterView = self.footerView;
    weakSelf.tableView.mj_footer.state = MJRefreshStateNoMoreData;//停止
}else {
    weakSelf.tableView.tableFooterView = [UIView new];
    [weakSelf.tableView.mj_footer resetNoMoreData];//重启
}

你可能感兴趣的:(MJRefresh使用教程)