UITableView实现上拉加载更多
2016-01-07 10:42
591 查看
//
创建表格底部
- (void) createTableFooter
{
myTableView.tableFooterView
=
nil;
UIView
*tableFooterView = [[UIView
alloc]
initWithFrame:CGRectMake(0.0f,
0.0f,
myTableView.bounds.size.width,
40.0f)];
UILabel *loadMoreText = [[UILabel
alloc]
initWithFrame:CGRectMake(0.0f,
0.0f,
116.0f,
40.0f)];
[loadMoreText
setCenter:tableFooterView.center];
[loadMoreText
setFont:[UIFont
fontWithName:@"Helvetica Neue"
size:14]];
[loadMoreText
setText:@"上拉显示更多数据"];
[tableFooterView
addSubview:loadMoreText];
myTableView.tableFooterView
= tableFooterView;
}
- (void)scrollViewDidEndDragging:(UIScrollView
*)scrollView willDecelerate:(BOOL)decelerate
{
//
下拉到最底部时显示更多数据
if(!_loadingMore
&& scrollView.contentOffset.y
> ((scrollView.contentSize.height
- scrollView.frame.size.height)))
{
NSLog(@"开始加载");
[self
loadDataBegin];
}
}
//
开始加载数据
- (void) loadDataBegin
{
if (_loadingMore
==
NO)
{
_loadingMore =
YES;
UIActivityIndicatorView *tableFooterActivityIndicator = [[UIActivityIndicatorView
alloc]
initWithFrame:CGRectMake(75.0f,
10.0f,
20.0f,
20.0f)];
[tableFooterActivityIndicator
setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
[tableFooterActivityIndicator
startAnimating];
[searchTableView.tableFooterView
addSubview:tableFooterActivityIndicator];
NSLog(@"正在加载");
[self
loadDataing];
}
}
//
加载数据中
- (void) loadDataing
{
/**
*要处理的事件
*/
[self
loadDataEnd];
}
//
加载数据完毕
- (void) loadDataEnd
{
NSLog(@"加载完毕");
_loadingMore =
NO;
[self
createTableFooter];
}
创建表格底部
- (void) createTableFooter
{
myTableView.tableFooterView
=
nil;
UIView
*tableFooterView = [[UIView
alloc]
initWithFrame:CGRectMake(0.0f,
0.0f,
myTableView.bounds.size.width,
40.0f)];
UILabel *loadMoreText = [[UILabel
alloc]
initWithFrame:CGRectMake(0.0f,
0.0f,
116.0f,
40.0f)];
[loadMoreText
setCenter:tableFooterView.center];
[loadMoreText
setFont:[UIFont
fontWithName:@"Helvetica Neue"
size:14]];
[loadMoreText
setText:@"上拉显示更多数据"];
[tableFooterView
addSubview:loadMoreText];
myTableView.tableFooterView
= tableFooterView;
}
- (void)scrollViewDidEndDragging:(UIScrollView
*)scrollView willDecelerate:(BOOL)decelerate
{
//
下拉到最底部时显示更多数据
if(!_loadingMore
&& scrollView.contentOffset.y
> ((scrollView.contentSize.height
- scrollView.frame.size.height)))
{
NSLog(@"开始加载");
[self
loadDataBegin];
}
}
//
开始加载数据
- (void) loadDataBegin
{
if (_loadingMore
==
NO)
{
_loadingMore =
YES;
UIActivityIndicatorView *tableFooterActivityIndicator = [[UIActivityIndicatorView
alloc]
initWithFrame:CGRectMake(75.0f,
10.0f,
20.0f,
20.0f)];
[tableFooterActivityIndicator
setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
[tableFooterActivityIndicator
startAnimating];
[searchTableView.tableFooterView
addSubview:tableFooterActivityIndicator];
NSLog(@"正在加载");
[self
loadDataing];
}
}
//
加载数据中
- (void) loadDataing
{
/**
*要处理的事件
*/
[self
loadDataEnd];
}
//
加载数据完毕
- (void) loadDataEnd
{
NSLog(@"加载完毕");
_loadingMore =
NO;
[self
createTableFooter];
}
相关文章推荐
- 简单实用Handler传递数据并且更新UI界面
- easyUI自定义DataGrid分页栏
- AJAX POST请求中参数以form data和request payload形式在servlet中的获取方式
- Hibernate继承映射的“Could not format discriminator value to SQL string”错误解决方法
- 1.UIButton的基本使用
- EasyUi心得
- Understanding Steering Behaviors: Queue
- 构建一个倒排索引 A first take at building an inverted index
- UITableView中刷新单行cell与单个section段的方法
- UIAlertView、 UIActionSheet
- 拖动条控件 (UISlider)
- 进度环控件 (UIActivityIndicatorView)
- 进度条控件 (UIProgressView)
- 图像控件 (UIImageView)
- UE4 Socket多线程非阻塞通信【2】
- 分段控件 (UISegmentedControl)
- diskimage-builder的容器镜像
- WeChat demo 麦子学院课程笔记 UI部分
- 初学UEditor
- 事件处理, UIControl的子类