您的位置:首页 > 其它

关于页面的下拉刷新,和上拉加载 --- > collectionView ,tableView

2015-10-14 19:21 337 查看
1 )上拉加载 MJRefreh三方库

-(void)headAdd

{

NSInteger num = 0;

NSString *str = [NSString stringWithFormat:@"http://open4.bantangapp.com/topic/list",++num];

[self.collectionView addFooterWithCallback:^{

[ReadAsync readAsyncWithwebStr:str parmater:nil block:^(NSData *data) {

NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];

NSDictionary *dic1 = [dic objectForKey:@"data"];

NSArray *array = [dic1 objectForKey:@"topic"];

for (NSDictionary *dictionary in array) {

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

[model setValuesForKeysWithDictionary:dictionary];

[self.imageArray addObject:model];

}

[self.collectionView reloadData];

}];

[self.collectionView footerEndRefreshing];

}];

}

2). 下拉刷新 ;在数据解析的block里移除存放数据的数组里的元素;下拉刷新只舒心第一页的数据

-(void)footRefesh

{

// 添加下拉刷新头部控件

[self.collectionView addHeaderWithCallback:^{

[ReadAsync readAsyncWithwebStr:@“http://baidu.com“ parmater:nil block:^(NSData *data) {

[self.imageArray removeAllObjects];

NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];

NSDictionary *dic1 = [dic objectForKey:@"data"];

NSArray *array = [dic1 objectForKey:@"topic"];

for (NSDictionary *dictionary in array) {

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

[model setValuesForKeysWithDictionary:dictionary];

[self.imageArray addObject:model];

}

[self.collectionView reloadData];

}];

// 结束刷新

[self.collectionView headerEndRefreshing];

}];

#pragma mark --自动刷新(一进入程序就下拉刷新)

[self.collectionView headerBeginRefreshing];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: