Ega Setya Putra
Ega Setya Putra

Reputation: 1695

Add loading footer on UITableView

I have a UITableView. When I scroll to the bottom it loads more data. How can I add a loading animation to the footer of the table when it´s scrolled to the bottom?

Upvotes: 1

Views: 2798

Answers (3)

poojathorat
poojathorat

Reputation: 1220

You can use MNMBottomPullToRefreshManager file to load more data. First you have to initialize it in viewDidLoad as

pullToRefreshManager_ = [[MNMBottomPullToRefreshManager alloc] initWithPullToRefreshViewHeight:60.0f tableView:table withClient:self];


- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[pullToRefreshManager_ tableViewScrolled];
}


- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate: (BOOL)decelerate
 {
[pullToRefreshManager_ tableViewReleased];
}


- (void)bottomPullToRefreshTriggered:(MNMBottomPullToRefreshManager *)manager
{
    //method to get more data 
   // [self CallWebServiceToLoadMorePAYMENTS];

}
}

After reloading your tableView call:

[pullToRefreshManager_ tableViewReloadFinished];

Upvotes: 2

Tanuj
Tanuj

Reputation: 531

Use this:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    if(array.count>1){
            if(indexPath.row == array.count-1){
                [self setupTableViewFooter];
            }
    }
}


- (void)setupTableViewFooter
{
    // set up label
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.navigationController.navigationBar.frame.size.height)];
    footerView.backgroundColor = [UIColor clearColor];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
    label.font = [UIFont fontWithName:Font_MuseoSans size:14];
    label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    label.textColor = [UIColor darkGrayColor];
    label.text = @"Loading";

    self.footerLabel = label;
    CGSize labelSize = [self.footerLabel sizeThatFits:footerView.frame.size];
    [footerView addSubview:self.footerLabel];

    // set up activity indicator
    UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    activityIndicatorView.hidesWhenStopped = YES;
    activityIndicatorView.color = [UIColor blackColor];

    self.activityIndicator = activityIndicatorView;
    [self.activityIndicator startAnimating];

    [footerView addSubview:self.activityIndicator];

    CGRect footerFrame = footerView.frame;
    label.frame = CGRectMake((footerFrame.size.width-labelSize.width - 4 - activityIndicatorView.frame.size.width)/2, (footerFrame.size.height-labelSize.height)/2
                             , (footerFrame.size.width-labelSize.width - 4 - activityIndicatorView.frame.size.width), labelSize.height);
    self.activityIndicator.frame = CGRectMake(label.frame.origin.x + labelSize.width + 4, (footerFrame.size.height-activityIndicatorView.frame.size.height)/2
                                              , activityIndicatorView.frame.size.width, activityIndicatorView.frame.size.height);

    self.tableView.tableFooterView = footerView;
}

Upvotes: 1

iAnurag
iAnurag

Reputation: 9346

Try this

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { 
UIView *headerView = [[[UIView alloc] init]autorelease];

[headerView setBackgroundColor:[UIColor clearColor]];

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self 
       action:@selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Load More" forState:UIControlStateNormal];
button.frame = CGRectMake(10.0, 210.0, 160.0, 40.0);


[headerView addSubview:button];


return headerView;

}  

Upvotes: 2

Related Questions