且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在UITableView底部添加活动指示器?

更新时间:2023-12-05 17:45:58

让我们试试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];
   }

}

谢谢!