Add activity indicator at bottom of UITableView?

12,583

Solution 1

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

For example :

Declare UIView * footerView; in .h file

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

}

Thanks!

Solution 2

check out this open source project.its may help you...

https://github.com/dkSolutions/DKPaginatedTableView

Share:
12,583
Sugan S
Author by

Sugan S

Updated on July 27, 2022

Comments

  • Sugan S
    Sugan S almost 2 years

    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.

  • Sugan S
    Sugan S about 10 years
    thank you friend let me try @Natarajan
  • HotFudgeSunday
    HotFudgeSunday almost 9 years
    This is the best solution I've seen so far for this problem. Good for you for adding useful answers instead of winey criticism like the people who down pointed this question.