我正在使用UITableviewCell
在我的应用程序项目中创建配置文件表单。所以为此我使用了一个单元。自定义单元由UITextField
组成。最初这些字段被填充了Web服务。UITextField在“自定义表格”视图中的值在向上滚动和向下滚动时发生更改
现在我可以编辑的全名,如下图所示:
你可以看到我已经在全名字段中键入劳尔。
但是,如果我向上滚动表格视图并向下滚动,我失去了我更改的值,并显示第一个文本字段中的旧条目。
我使用下面的代码:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// create a new cell if needed or reuse an old one
let regCell = profileManagement.dequeueReusableCell(withIdentifier:"regFirstCell", for: indexPath)as? RegistrationFieldTableViewCell
regCell?.registrationField.tag = indexPath.row
regCell?.registrationFieldImage.image = fieldImages[indexPath.row]
let nameFields = NSLocalizedString(regFieldsNames[indexPath.row], comment: "")
regCell?.registrationField.placeholder = nameFields
regCell?.registrationField.autocorrectionType = .no
regCell?.registrationField.keyboardType = UIKeyboardType.default
regCell?.showPassword.isHidden = true
//Swith case for giving keypad to textfields
switch indexPath.row {
case 0:
regCell?.registrationField.text = self.name
case 1:
regCell?.registrationField.text = self.emailId
case 2:
regCell?.registrationField.text = self.civilId
regCell?.registrationField.isUserInteractionEnabled = false
case 3:
regCell?.registrationField.text = self.phoneNumber
regCell?.registrationField.isUserInteractionEnabled = false
case 4:
regCell?.registrationField.isSecureTextEntry = true
regCell?.registrationField.text = "abhijith123"
regCell?.showPassword.isHidden = true
regCell?.registrationField.isUserInteractionEnabled = false
default:
print("Something else")
}
return regCell!
}
当你输入一个新的值时,你用什么代码来保存它? –
目前我没有使用任何代码来存储新的值。请建议这个怎么办 –