我有三种自定义单元格类型 - 一种带有文本字段的单元格,另一种带有日期字段,另一种带有选择器字段。
我在这里捕获数据变化:
func textFieldDidEndEditing(_ textField: UITextField) {
print("TextField did end editing method called")
switch segmentedControl.selectedSegmentIndex {
case 0:
currentItem.setObject(itemName, forKey: "itemName")
.....
currentItem.setObject(serialNumber, forKey: "serialNumber")
break
case 1:
currentItem.setObject(username, forKey: "username")
currentItem.setObject(email, forKey: "email")
...
break
“currentItem”是一个 CKRecord。
这是错误的。字段(itemName、serialNumber 等)是字符串。它们使用云数据在 ViewDidLoad 中设置。
如何正确更新这些字段
提前致谢
最佳答案
正如 Subin K Kuriakose 在评论中所说,您应该使用 UITextField
的 tag
属性来确定它是哪个文本字段。
您需要在创建文本字段单元格时设置tag
属性。只需在某处保留一个变量并在每次创建文本字段时递增它,并将 tag
设置为该变量:
textFieldCount += 1
myCustomCell.textField.tag = textFieldCount
类似的东西,你明白了。
现在表格 View 中的每个文本字段都有一个唯一的标签。在 textFieldDidEndEditing
中,您检查标签:
switch textField.tag {
case 1:
// it's the first text field!
case 2:
// it's the second text field!
case 3:
// it's the third text field!
default:
break
}
很简单!
关于ios - Swift - 如何识别哪个自定义 tableview 单元格已被修改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38036783/