[英]How can I test if a custom cell has been registered with the tableView?
[英]Swift - How can I identify which custom tableview cell has been modified?
我有三種自定義單元格類型-一個帶有文本字段的單元格,另一個帶有日期字段的單元格,另一個帶有選取器字段的單元格。
我在這里捕獲數據更改:
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
這樣的事情,你就明白了。
現在,表格視圖中的每個文本字段都有一個唯一的標記。 在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
}
這很簡單!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.