【发布时间】:2020-06-13 17:12:39
【问题描述】:
我有一个表格视图单元格,里面有一个文本字段。
我希望它在插入行后成为第一响应者。但是插入完成后有没有明确的方法来获得回调?
我尝试在单元格的 viewWilDisplay 中调用 textField 的 becomeFirstResponder,结果只是冻结了 UI
【问题讨论】:
标签: uitableview uiview uikit first-responder
我有一个表格视图单元格,里面有一个文本字段。
我希望它在插入行后成为第一响应者。但是插入完成后有没有明确的方法来获得回调?
我尝试在单元格的 viewWilDisplay 中调用 textField 的 becomeFirstResponder,结果只是冻结了 UI
【问题讨论】:
标签: uitableview uiview uikit first-responder
尝试使用batch update 插入行。该函数具有完成块,因此您可以从那里调用 becomeFirstResponder。
【讨论】:
我知道这有点傻,但对我很有帮助。
首先创建一个 tempObject 来存储新行的 int 值。 例如:
var insertCellIndex : Int = -1
在 cellforIndex 方法中:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
if self.insertCellIndex == indexPath.row
{
// make your textfield become first responder
}
else
{
print("nothing")
}
}
借助按钮插入新行
@IBAction func btnApplyFilterClicked(_ sender: Any)
{
self.arrTemp.append("test") // insert in array
self.insertCellIndex = self.arrTemp.count - 1
self.tblView.reloadData()
}
【讨论】: