Ios 如何使用didSelectRowAt访问多个自定义单元格
我试图在我的2个自定义单元格中访问textView,但我不确定如何访问它。我知道以下内容适用于1种类型的自定义单元格Ios 如何使用didSelectRowAt访问多个自定义单元格,ios,swift,uitableview,Ios,Swift,Uitableview,我试图在我的2个自定义单元格中访问textView,但我不确定如何访问它。我知道以下内容适用于1种类型的自定义单元格 override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let cell = try tableView.dequeueReusableCell(withIdentifier: "Cell1") as! ImageNotesCell
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = try tableView.dequeueReusableCell(withIdentifier: "Cell1") as! ImageNotesCell
cell.notes.isEditable = true
}
但是我不知道如何使用名为NotesCell
的自定义类为我的另一个自定义单元格添加选择。是否有办法将两个单元格都放在didSelectRowAt
中,以便我可以访问它们各自的UITextView
编辑:对于我正在创建的应用程序,单元格类型可以是两种类型中的一种,没有特定顺序要访问
didSelectRowAt
中的单元格,可以执行以下操作:
let indexPath1 = IndexPath(row: 0, section: 0)
let cell1 = tableView.cellForRow(at: indexPath1) as! ImageNotesCell
let indexPath2 = IndexPath(row: 1, section: 0)
let cell2 = tableView.cellForRow(at: indexPath2) as! ImageNotesCell
let cell = tableView.cellForRow(at: indexPath)
if cell is ImageNotesCell {
print("ImageNotesCell")
} else if cell is NotesCell {
print("NotesCell")
}
如果要检查单元格的类型,可以执行以下操作:
let indexPath1 = IndexPath(row: 0, section: 0)
let cell1 = tableView.cellForRow(at: indexPath1) as! ImageNotesCell
let indexPath2 = IndexPath(row: 1, section: 0)
let cell2 = tableView.cellForRow(at: indexPath2) as! ImageNotesCell
let cell = tableView.cellForRow(at: indexPath)
if cell is ImageNotesCell {
print("ImageNotesCell")
} else if cell is NotesCell {
print("NotesCell")
}
但是如果您不需要单元格内的值,那么您应该从填充
表视图的模型数组中获取这些值。您不能从单元格访问文本视图。您可以从数据模型中访问文本。@rmaddy如果您能解释一下,这对学习iOS开发的人来说是非常好的。这个问题的另一个更大的问题是,我试图记录对这些文本视图的更改,以便更新我拥有的数据库。实际上,我试图跟踪单元格中修改后的值,这对我有很大帮助。谢谢