這是一個(gè)刷新控件,帶有占位符刷新!github地址IHFRefresh.
用法關(guān)鍵:
1.刷新:可以對(duì)TableView 和 CollectionView 進(jìn)行刷新,一開(kāi)始設(shè)置頭部或者尾部并且刷新的方法,在刷新結(jié)束后調(diào)用[endRefresh] 進(jìn)行結(jié)束
2:占位符:
調(diào)用 - (void)reloadDataWithEmptyData; 可以對(duì) TableView 和 CollectionView 的數(shù)據(jù)加載, 如果數(shù)據(jù)源為空,則會(huì)根據(jù)IHEmptyDataView的樣式出現(xiàn)對(duì)用戶進(jìn)行提醒。
可以調(diào)用 - (void)reloadDataWithEmptyDataViewTitle:(NSString *)title buttonTitle:(NSString *)buttonTitle; 更改Title和Button的title對(duì)用戶提示。
Button 默認(rèn)做Headerview的加載,但是如果你要實(shí)現(xiàn)你的方法,可以使用
_tableView.refreshOperation = ^(){
[weakSelf doCustomAction];
};
刷新
****1 . 下拉刷新****
方法一: 使用block(一句話)
- (void)setupHeaderWithMethod1 {
__weak __typeof(self) weakSelf = self;
_tableView.refreshHeader = [IHFRefreshHeaderView headerWithRefreshingOperation:^{
// refresh action
[weakSelf reloadTableViewData:nil];
}];
}
方法二:使用Block(將上述的一句話分開(kāi))
- (void)setupHeaderWithMethod2 {
__weak __typeof(self) weakSelf = self;
_tableView.refreshHeader = [IHFRefreshHeaderView refreshView];
_tableView.refreshHeader.refreshingOperation = ^(){
// refresh action
[weakSelf reloadTableViewData:nil];
};
}
方法三:使用Perform action(一句話)
- (void)setupHeaderWithMethod3 {
_tableView.refreshHeader = [IHFRefreshHeaderView headerWithRefreshingTarget:self refreshingAction:@selector(reloadTableViewData:)];
}
方法四: 使用Perform action(分開(kāi)一句話)
- (void)setupHeaderWithMethod4 {
_tableView.refreshHeader = [IHFRefreshHeaderView refreshView];
[_tableView.refreshHeader addTarget:self refreshAction:@selector(reloadTableViewData:)];
}
1.可以使用 autoRefreshWhenViewDidAppear , 在初次加載頁(yè)面時(shí)進(jìn)行一次下拉刷新
2.可以調(diào)用beginRefreshing 進(jìn)行一次刷新
****2 上拉刷新(一般是加載更多)****
方法一
- (void)setupFooterWithMethod1 {
__weak __typeof(self) weakSelf = self;
_tableView.refreshFooter = [IHFRefreshFooterView refreshView];
_tableView.refreshFooter.refreshingOperation = ^(){
[weakSelf loadMore];
};
}
方法二
- (void)setupFooterWithMethod2 {
__weak __typeof(self) weakSelf = self;
_tableView.refreshFooter = [IHFRefreshFooterView footerWithRefreshingOperation:^{
[weakSelf loadMore];
}];
}
方法三
-(void)setupFooterWithMethod3{
_tableView.refreshFooter = [IHFRefreshFooterView refreshView];
[_tableView.refreshFooter addTarget:self refreshAction:@selector(loadMore)];
}
方法四
- (void)setupFooterWithMethod4 {
_tableView.refreshFooter = [IHFRefreshFooterView footerWithRefreshingTarget:self refreshingAction:@selector(loadMore)];
}
注意:無(wú)論是上拉還是下拉刷新,在做完刷新操作后,都要調(diào)用endRefresh進(jìn)行結(jié)束
占位符刷新
占位符刷新值的是當(dāng)請(qǐng)求數(shù)據(jù)是空的時(shí)候 會(huì)出現(xiàn) 提示文字 和 提示按鈕 來(lái)提示用戶!
刷新調(diào)用
[self.tableView reloadDataWithEmptyData];
// 樣式是IHEmptyDataView.xib --- 可自己更換圖片和按鈕的樣式
更改方法為
方法1: 更改XIB (不推薦)
方法2:
//使用該方法來(lái)刷新數(shù)據(jù)源
[self.tableView reloadDataWithEmptyDataViewTitle:@"沒(méi)有數(shù)據(jù)?" buttonTitle:@"load"];
注意:
點(diǎn)擊提示按鈕會(huì)調(diào)用 下拉刷新方法
如果你想自定義調(diào)用方法
方法1:
- (void)ifNeedcustomButtonClickAction1 {
// If call the method , it will do the Block method , else it will do the header refresh method!
__weak __typeof(self) weakSelf = self;
_tableView.refreshOperation = ^(){
[weakSelf doCustomAction];
};
}
方法2:
-(void)ifNeedcustomButtonClickAction2{
[_tableView addTarget:self refreshAction:@selector(doCustomAction)];
}