标签:
#pragma mark - 刷新
//下拉刷新
- (void)setUpRefresh
{
//用MJReference框架
//下拉刷新
_tableView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(getHotSchoolData)];
//开始刷新
[_tableView.header beginRefreshing];
//上拉刷新
MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(getMoreData)];
//显示多少百分比就开始刷新
self.tableView.footer = footer;
}
#pragma mark - 获取数据
- (void)getHotSchoolData
{
__weak __typeof(self) weakSelf = self;
[[HotModel singleton] getHotSchoolList:^{
weakSelf.dataArray= [[HotModel singleton] hotSchoolArr];
[weakSelf.tableView reloadData];
[weakSelf.tableView.header endRefreshing];
} failedBlock:^(NSString *state, NSString *errmsg) {
[weakSelf.tableView.header endRefreshing];
}];
}
- (void)getMoreData
{
__weak __typeof(self) weakSelf = self;
if (self.dataArray.count != 0) {
ZSLog(@"1=====%ld",self.dataArray.count);
[[HotModel singleton] getMoreHotSchool:^{
ZSLog(@"2=====%ld",self.dataArray.count);
NSArray *newData = [[HotModel singleton] hotSchoolArr];
[weakSelf.dataArray addObjectsFromArray:newData];
ZSLog(@"3=====%ld",weakSelf.dataArray.count);
[weakSelf.tableView reloadData];
[weakSelf.tableView.footer endRefreshing];
} failedBlock:^(NSString *state, NSString *errmsg) {
[weakSelf.tableView.footer endRefreshing];
}];
}
}
问题:每次加载10条数据,上拉时1处打印总是20;2处总是打印10;3处打印20
解决:单利的内存 是全局唯一的
- (void)getHotSchoolData
{
__weak __typeof(self) weakSelf = self;
[[HotModel singleton] getHotSchoolList:^{
[weakSelf.dataArray addObjectsFromArray:[[HotModel singleton] hotSchoolArr]];
[weakSelf.tableView reloadData];
[weakSelf.tableView.header endRefreshing];
} failedBlock:^(NSString *state, NSString *errmsg) {
[weakSelf.tableView.header endRefreshing];
}];
}
标签:
原文地址:http://www.cnblogs.com/HMJ-29/p/5364343.html