UITableView实现上拉加载更多

来源:互联网 发布:飞鸽传书需要网络吗 编辑:程序博客网 时间:2024/05/29 06:32
//创建表格底部
- (void) createTableFooter
{
   
   myTableView.tableFooterView= nil;
   
   UIView *tableFooterView = [[UIViewalloc]initWithFrame:CGRectMake(0.0f,0.0f,myTableView.bounds.size.width,40.0f)];
   
   
UILabel *loadMoreText = [[UILabelalloc]initWithFrame:CGRectMake(0.0f,0.0f,116.0f,40.0f)];
   
    [loadMoreText
setCenter:tableFooterView.center];
   
    [loadMoreText
setFont:[UIFontfontWithName:@"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(@"开始加载");
       
        [
selfloadDataBegin];
       
    }
   
}

//开始加载数据
- (void) loadDataBegin

{
   
   
if (_loadingMore== NO)
       
    {
       
       
_loadingMore = YES;
       
       
UIActivityIndicatorView *tableFooterActivityIndicator = [[UIActivityIndicatorViewalloc]initWithFrame:CGRectMake(75.0f,10.0f,20.0f,20.0f)];
       
        [tableFooterActivityIndicator
setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
       
        [tableFooterActivityIndicator
startAnimating];
       
        [
searchTableView.tableFooterViewaddSubview:tableFooterActivityIndicator];
       
       
NSLog(@"正在加载");
       
        [
selfloadDataing];
       
    }
   
}

//加载数据中
- (void) loadDataing
{
   /**
     *要处理的事件
     */
     [selfloadDataEnd];
}


//加载数据完毕
- (void) loadDataEnd
{
   
NSLog(@"加载完毕");
   
   
_loadingMore = NO;
   
    [
selfcreateTableFooter];
   
}
0 0
原创粉丝点击