【发布时间】:2022-01-06 16:48:21
【问题描述】:
我在 tableview 中有 textview。我想在按下返回键时移动到下一个 textview。现在我可以将 tableview 滚动到下一个索引,但活动 textview 的状态没有更新。
代码如下:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "editorCell", for: indexPath) as? EditorTableViewCell else{return UITableViewCell()}
cell.textView.delegate = self
return cell
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return pageCount
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return tableView.bounds.height
}
func textViewDidChange(_ textView: UITextView) {
if textView.text.contains(where: {$0 == "\n"}){
self.tableView.scrollToRow(at: IndexPath(row: 1, section: 0), at: .top, animated: true)
self.tableView.layoutIfNeeded()
self.tableView.reloadData()
}
}
在 textViewDidChange 中,我尝试移动到索引 1 处的 textview,但是当我键入字符时,它会写入索引 0 处的 textview。我无法在单元格中切换 textview 的活动状态。
【问题讨论】: