您的位置:首页 > 产品设计 > UI/UE

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];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: