IHFRefresh - 帶占位符的刷新控件

這是一個(gè)刷新控件,帶有占位符刷新!github地址IHFRefresh.

用法關(guān)鍵:
1.刷新:可以對(duì)TableView 和 CollectionView 進(jìn)行刷新,一開始設(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(將上述的一句話分開)

- (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(分開一句話)

- (void)setupHeaderWithMethod4 {

  _tableView.refreshHeader = [IHFRefreshHeaderView refreshView];
  [_tableView.refreshHeader addTarget:self refreshAction:@selector(reloadTableViewData:)];
}

1.可以使用 autoRefreshWhenViewDidAppear , 在初次加載頁面時(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)];
}

注意:無論是上拉還是下拉刷新,在做完刷新操作后,都要調(diào)用endRefresh進(jìn)行結(jié)束


占位符刷新


占位符刷新值的是當(dāng)請(qǐng)求數(shù)據(jù)是空的時(shí)候 會(huì)出現(xiàn) 提示文字 和 提示按鈕 來提示用戶!

刷新調(diào)用

[self.tableView reloadDataWithEmptyData];

// 樣式是IHEmptyDataView.xib --- 可自己更換圖片和按鈕的樣式
更改方法為
方法1: 更改XIB (不推薦)
方法2:

//使用該方法來刷新數(shù)據(jù)源
[self.tableView reloadDataWithEmptyDataViewTitle:@"沒有數(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)];
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 12,255評(píng)論 4 61
  • 關(guān)注了改變自己有很長一段時(shí)間了。大概是從公眾號(hào)剛剛興起的時(shí)候就關(guān)注的。今年年初的時(shí)候,再次覺得有必要深入學(xué)習(xí)和了解...
    幺歌閱讀 257評(píng)論 0 0
  • 昨天鬧鐘調(diào)錯(cuò)了結(jié)果多睡了半小時(shí),我也真是看書看暈了。 下午有個(gè)妹子加我好友,問我是不是明年考而且買了資料,我本來直...
    彈彈彈閱讀 296評(píng)論 0 1
  • 文 丨 九月柚子 你比你想象的更美麗。 ——遇見你是最美麗的意外。 · 2015初見你。 2015開...
    九月柚子閱讀 1,039評(píng)論 7 9
  • 霧靄迷蒙,愁雨絲絲淋著輕愁,惆悵還依舊。如泣蟬聲,乘著風(fēng),鉆進(jìn)了盛夏的狹縫。我拾著腳步,聞著永福寺晨曉的鐘聲...
    panjw閱讀 442評(píng)論 0 3