简体   繁体   中英

WillDisplayFooterView UITableView does not execute

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM