0

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

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

这就是我添加页脚视图的方式:

    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,但从未执行过“加载”。当显示 footerView 时如何通知我?

4

1 回答 1

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

斯威夫特版本:

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
}

原帖在这里

于 2017-10-25T18:31:54.130 回答