【问题标题】:UITableView scroll to not-existsing cell programmaticallyUITableView 以编程方式滚动到不存在的单元格
【发布时间】:2016-10-15 12:46:39
【问题描述】:

我的表格视图包含 20 个单元格。屏幕只放置了8个单元格,所以这个函数

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell

调用 8 次,我只填充前 8 个单元格。

这个方法也调用了8次:

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
            if (indexPath.row == 11)
            {
                tableView.scrollToRow(at: indexPath, at: .top, animated: true)
            }
        }

我还没有 indexPath.row == 11。 如何滚动到第 11 个单元格?

【问题讨论】:

  • 你用的是swift 3.0吗?
  • 给我看你的全部代码。

标签: ios swift uitableview scroll


【解决方案1】:

创建索引路径let indexPath = NSIndexPath(forRow: 11, inSection: 0)

然后将此 indexPath 传递为 self.tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: .Top, animated: false)

这将自动滚动到 indexPath 中提到的所需单元格。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-24
    • 2021-09-02
    • 1970-01-01
    • 2020-10-18
    • 2011-08-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多