在UITableView底部添加活动指示器? [英] Add activity indicator at bottom of UITableView?

查看:85
本文介绍了在UITableView底部添加活动指示器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有UITableview的分页,首先会从服务器获取20个对象,并将填入UITableView,然后当它到达最后一行时需要进行另一个服务调用以获取下一个20个对象。我的问题是我需要在底部添加活动指示器我的表应该说正在加载,用户可以向上滚动查看当前对象但不应向下滚动。是否有任何自定义控件?
有没有最好的方法来实现它?。提前谢谢。

I have UITableview with pagination like first will get 20 objects from server and will populate in UITableView then when it reaches last row need to make another service call to get next 20 objects.My problem is I need to add activity indicator at bottom of my table and should say "Loading",User can scroll to up to view current objects but should not scroll down.Is there any custom control? Is there any best way to achieve it?.Thanks in advance.

推荐答案

让我们试试TableView页脚视图来显示活动指标。

Let's Try TableView Footer View to show activity indicator.

例如:

声明UIView * footerView;在.h文件中

Declare UIView * footerView; in .h file

在.m文件中添加以下方法

Add Following methods in .m file

 - (void)viewDidLoad
 {
     [super viewDidLoad];

     [self initFooterView];
 }

 -(void)initFooterView
 {
    footerView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 40.0)];

    UIActivityIndicatorView * actInd = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

    actInd.tag = 10;

    actInd.frame = CGRectMake(150.0, 5.0, 20.0, 20.0);

    actInd.hidesWhenStopped = YES;

    [footerView addSubview:actInd];

    actInd = nil;
 }

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
     BOOL endOfTable = (scrollView.contentOffset.y >= ((self.contentArray.count * 40) - scrollView.frame.size.height)); // Here 40 is row height

    if (self.hasMoreData && endOfTable && !self.isLoading && !scrollView.dragging && !scrollView.decelerating)
   {
        self.tableView.tableFooterView = footerView;

        [(UIActivityIndicatorView *)[footerView viewWithTag:10] startAnimating];
   }

}

谢谢!

这篇关于在UITableView底部添加活动指示器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆