WillDisplayFooterView UITableView不会执行

时间:2017-10-25 18:04:12

标签: ios swift uitableview tablefooterview

我将委托和数据源设置为self。这是我想要运行的代码:

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

这是我添加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

我可以看到footerView,但从不执行“load”。如何在显示footerView时收到通知?

1 个答案:

答案 0 :(得分:-1)

试试这个

目标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版本:

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
}

原帖是here