求助!开发环境xcode8
,我的数据库中有两千多条数据,我在服务的设置的每页200条,我用MJRefresh
库实现上拉加载数据只加载前2页数据,再上拉后面就不加载了,请各位老师给看看代码不知是不是逻辑上有错误~!谢谢~!!
伪代码如下:
SSTQuanDataModel.h
:
@interface SSTQuanDataModel : NSObject
...
...
//总页数
@property(nonatomic,assign)NSInteger total_num;
//当前页码
@property(nonatomic,assign)NSInteger currentPage;
...
@end
SSTQuanZhiBoViewController.m
:
...
#impor “SSTQuanDataModel”
#import <MJExtension.h>
#import <MJRefresh.h>
@interface SSTQuanViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property(nonatomic,strong)UICollectionView *collectionVC;
@property(nonatomic,strong)NSMutableArray *quanData;
@property(nonatomic,strong)AFHTTPSessionManager *manager;
....
@end
@implementation SSTQuanViewController
....
//上拉加载数据
-(void)setupReFresh{
//上拉加载数据
self.collectionVC.mj_footer=[MJRefreshBackFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
}
//上拉刷新加载更多数据
-(void)loadMoreData{
SSTQuanDataModel *sd=[[SSTQuanDataModel alloc]init];
sd.currentPage=1;
NSString *url =[NSString stringWithFormat:@"http://127.0.0.1:8000/api/v1/coupon/?page=%ld",++sd.currentPage] ;
[self.manager GET:url parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSArray *add=[SSTQuanDataModel mj_objectArrayWithKeyValuesArray:responseObject[@"results"]];
//下拉刷新后将第二页的数据添加到self.quanData的后面
[self.quanData addObjectsFromArray:add];
[self.collectionVC reloadData];
//停止刷新表格
if(self.quanData.count==sd.total_num){
[self.collectionVC.mj_footer endRefreshingWithNoMoreData];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//显示失败信息
[SVProgressHUD showErrorWithStatus:@"数据加载失败!"];
}];
}
....
@end
感谢 @空心菜舅舅 确实是自己在loadMoreData
方法中sd.currentPage=1
这句表达式的问题,这句应该在第一次加载网络请求的时候设置,自己的疏忽,非常感谢各位兄台不吝指教~!
sd.currentPage=1;
Setiap kali anda memuatkanMoreData, ia dimulakan ke halaman pertama, jadi halaman kedua data sentiasa keluar...Mesti masalah logik yang tiada kena mengena dengan MJ, MJ cuma kawalan
Bagaimana saya boleh mengubah suai ini? ?