使用出队的dequeueReusableCell-出队后的单元格的textField

问题描述

我正在使用的VC具有可变数量的单元格。每个单元格都包含一种成分以及数量的百分比。我在textField键盘添加一个inputAccessoryView按钮,其中有一个next按钮,可以导航到下一行的textField。

一切正常,但是当屏幕上未加载单元格时我遇到了问题。

代码很简单:

func setNextResponder(for indexPath: IndexPath) {
    let index = IndexPath(row: indexPath.row + 1,section: 0)
    guard let nextCell = tableView.cellForRow(at: index) as? Cell
    else { return }
    nextCell.materialAmountTextField.becomeFirstResponder()
}

是否有强制VC加载该单元的内容?最好不必滚动到该单元格。

解决方法

我继续打电话给

DispatchQueue.main.async {
        self.tableView.scrollToRow(at: newIndexPath,at: .none,animated: true)
    }

在将下一个单元格的textField设置为第一响应者之前。