我有一个内部有文本字段的tableview单元。
我希望它在插入行后成为第一响应者。但是插入后没有明确的方法可以回叫吗?
我尝试在单元格的viewWilDisplay中调用textField的firstFirstResponder,并且冻结了UI
尝试用batch update插入行。该函数具有完成块,因此您可以从此处调用beginFirstResponder。
我知道这有点愚蠢,但对我有帮助。
首先创建一个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()
}