【问题标题】:WillDisplayFooterView UITableView does not executeWillDisplayFooterView UITableView 不执行
【发布时间】:2017-10-25 18:04:12
【问题描述】:

我将委托和数据源设置为 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,但从未执行过“加载”。当显示 footerView 时如何通知我?

【问题讨论】:

  • 该委托方法适用于节页脚,而不是表页脚。
  • 您必须在委托方法 viewForFooterInSection 和 heightForFooterInSection 中添加和设置您的页脚视图,然后将调用 willDisplayFooterView 函数。
  • "当显示 footerView 时如何通知我?"为什么需要通知您?您认为自己需要此类通知这一事实本身就是有问题的。
  • @matt 为什么会有这么大的问题?我的 footerView 是一个加载器视图。当用户滚动到底部时,他会看到加载器视图。如果我的程序知道他(将)看到加载器视图,我可以加载更多内容。
  • @JasperVisser 你问错问题了。您不在乎何时显示表格页脚。您想知道用户何时滚动到表格视图的底部。对该任务进行一些搜索并查看各种UIScrollViewDelegate 方法。

标签: ios swift uitableview tablefooterview


【解决方案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

【讨论】:

    猜你喜欢
    • 2011-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-12
    相关资源
    最近更新 更多