在一個項目開發過程中為了更好的體驗經常會用到下拉刷新更新數據,當然也伴隨一些上拉加載更多數據的情況;當前比較火的EGOTableViewPullRefresh只實現了下拉功能,而沒有上拉的功能。這里介紹一個同時集成下拉刷新和上拉加載更多的類庫EGOTableViewPullRefresh
英文原文和類庫下載地址:https://github.com/emreberge/EGOTableViewPullRefresh
附帶 Demo效果
容易集成,使用interface builder 添加tableView進行配置。
配置簡單, 箭頭頭像,背景顏色和文本顏色都能通過PullTableView類的屬性很容易的更改。
上拉加載更多數據功能在Table的底部。
可以通過代碼修改刷新和加載更多動畫。
添加 QuartzCore.framework 到你的工程中。
將 EGOTableViewPullRefresh 拖到你的工程目錄下。
查看 PullTableView.h 文件可用的屬性。
添加一個PullTableView 到你代碼中,實現PullTableViewDelegate委托方法。
欣賞吧。
創建一個新的xcode工程
選擇 View Based Application 模板(xcode 4.2以后版本是 Single View Application模板)
工程名字 EGOTableViewPullRefreshDemo
在工程文件下創建EGOTableViewPullRefreshDemoViewController控制器類(Single View Application模板不需這步)
添加 QuartzCore.framework 到工程中
拖拽 EGOTableViewPullRefresh 目錄下文件到工程支持的文件組下,確保(EGOTableViewPullRefresh)下文件都拷貝到目標文件組下。
拖一個UITableView控件到View視圖上.
打開 Identity inspector 將Table 的繼承類由 UITableView 改成PullTableView
連接 dataSources數據源和 pullDelegate協議到PullTableView的 File's owner上
添加 #import "PullTableView.h"
聲明 PullTableViewDelegate 和 UITableViewDataSource協議
創建一個屬性名為pullTableView的輸出口連接到interface Builder上的tableView上
在.m文件中添加下面代碼
#pragma mark - Refresh and load more methods
- (void) refreshTable
{
/*
Code to actually refresh goes here.
*/
self.pullTableView.pullLastRefreshDate = [NSDate date];
self.pullTableView.pullTableIsRefreshing = NO;
}
- (void) loadMoreDataToTable
{
/*
Code to actually load more data goes here.
*/
self.pullTableView.pullTableIsLoadingMore = NO;
}
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 5;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = [NSString stringWithFormat:@"Row %i", indexPath.row];
return cell;
}
- (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [NSString stringWithFormat:@"Section %i begins here!", section];
}
- (NSString *) tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
return [NSString stringWithFormat:@"Section %i ends here!", section];
}
#pragma mark - PullTableViewDelegate
- (void)pullTableViewDidTriggerRefresh:(PullTableView *)pullTableView
{
[self performSelector:@selector(refreshTable) withObject:nil afterDelay:3.0f];
}
- (void)pullTableViewDidTriggerLoadMore:(PullTableView *)pullTableView
{
[self performSelector:@selector(loadMoreDataToTable) withObject:nil afterDelay:3.0f];
}對于UI的配置,在ViewDidLoad()方法里面添加下面代碼(比如 修改刷新和上拉的背景色箭頭頭像等)
self.pullTableView.pullArrowImage = [UIImage p_w_picpathNamed:@"blackArrow"]; self.pullTableView.pullBackgroundColor = [UIColor yellowColor]; self.pullTableView.pullTextColor = [UIColor blackColor];
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。