Ios UITableView以编程方式滚动到不存在单元格

Ios UITableView以编程方式滚动到不存在单元格,ios,swift,uitableview,scroll,Ios,Swift,Uitableview,Scroll,我的tableview包含20个单元格。屏幕仅放置8个单元格,因此此功能 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 打了8次电话,我只填了前8个单元格 此方法也调用了8次: func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt

我的tableview包含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个单元格?

创建索引路径
让indexPath=NSIndexPath(forRow:11,第0节)

然后将此indexPath作为
self.tableView.ScrollToRowatineXpath(indexPath,atScrollPosition:.Top,动画:false)传递。


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

您是否使用了swift 3.0?显示您的全部代码。