0

I set the delegate and datasource to self. This is the code I want to run:

func tableView(_ tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) {
    print("load")
}

This is how I added the footerView:

    let footerView = UIView(frame: CGRect(x: 0, y: 0, width: table.frame.width, height: table.rowHeight))
    let loader = NVActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: table.frame.width, height: table.rowHeight), type: .ballScaleMultiple, color: .white)
    loader.startAnimating()
    loader.center = footerView.center
    footerView.addSubview(loader)
    table.tableFooterView = footerView

I can see the footerView, but "load" is never executed. How can I be notified when the footerView is presented?

Harjot Singh
  • 535
  • 7
  • 24
NoKey
  • 129
  • 11
  • 32
  • 2
    That delegate method is for section footers, not the table footer. – rmaddy Oct 25 '17 at 18:08
  • You have to add and setup your footer view in the delegate methods viewForFooterInSection and heightForFooterInSection, then the willDisplayFooterView func will be called. – Francesco Deliro Oct 25 '17 at 19:11
  • 1
    "How can I be notified when the footerView is presented?" Why do you need to be notified of that? The fact that you think you need such notification is itself problematic. – matt Oct 25 '17 at 19:14
  • @matt Why is that so problematic? My footerView is a loader view. When the user scrolls to the bottom, he sees the loader view. If my program knows he (will) see the loader view, I can load more content. – NoKey Oct 25 '17 at 22:41
  • @JasperVisser You are asking the wrong question. You don't care when the table footer is presented. You want to know when the user scrolls to the bottom of the table view. Do some searching on that task and look into the various `UIScrollViewDelegate` methods. – rmaddy Oct 26 '17 at 01:06

1 Answers1

-1

Try this

Objective C :-

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

    static CGFloat lastY = 0;

    CGFloat currentY = scrollView.contentOffset.y;
    CGFloat headerHeight = self.headerView.frame.size.height;

    if ((lastY <= headerHeight) && (currentY > headerHeight)) {
        NSLog(@" ******* Header view just disappeared");
    }

    if ((lastY > headerHeight) && (currentY <= headerHeight)) {
        NSLog(@" ******* Header view just appeared");
    }

    lastY = currentY; 
}

Swift Version:

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    var lastY: CGFloat = 0
    let currentY: CGFloat = scrollView.contentOffset.y
    let headerHeight: CGFloat? = headerView?.frame.size.height
    if (lastY <= headerHeight) && (currentY > headerHeight) {
        print(" ******* Header view just disappeared")
    }
    if (lastY > headerHeight) && (currentY <= headerHeight) {
        print(" ******* Header view just appeared")
    }
    lastY = currentY
}

Original Post is here

Harjot Singh
  • 535
  • 7
  • 24