//基本设置
1 在arc工程中,要创建pch文件,并且要import<UIKit/UIKit.h>
2 选中项目 - Project - Build Settings - ENABLE_STRICT_OBJC_MSGSEND 将其设置为 NO 即可
//使用的注意事项
1 receivedData 和dataSource一定要进行懒加载
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
//网络指示器开始转动
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
//当再次进行数据请求的时候一定要将receivedData的数据清空
if (self.receivedData ) {
[self.receivedData setData:nil];
}
}
2 当数据解析完成,已经放到数组中后一定要记得刷新
[self.tableView reloadData] // [self.collectionView reloadData]
3 当进行刷新时,清空数组的操作是在数据已经请求下来之后,在数据解析之前数组的清空
//用法
在viewDidLoad 中
[self refresh];
[self loadingMore];
//方法
- (void)refresh
{
[self.collectionView addHeaderWithCallback:^{
[self headerRefresh];
}];
[self.collectionView headerBeginRefreshing];
self.collectionView.headerPullToRefreshText = @"下拉可以刷新";
self.collectionView.headerReleaseToRefreshText = @"松开立即刷新";
self.collectionView.headerRefreshingText = @"正在刷新";
}
- (void)loadingMore
{
[self.collectionView addFooterWithCallback:^{
[self footerRefresh];
}];
self.collectionView.footerPullToRefreshText = @"上提可以加载";
self.collectionView.footerReleaseToRefreshText = @"松开立即刷新";
self.collectionView.footerRefreshingText = @"正在刷新";
[self.collectionView footerBeginRefreshing];
}
- (void)headerRefresh
{
self.pageNum = 1;
[self netWork];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.collectionView headerEndRefreshing];
});
}
- (void)footerRefresh
{
self.pageNum++;
[self netWork];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.collectionView footerEndRefreshing];
});
}