ios - 表格视图中的文本字段被清除
问题描述
我目前正在创建一个应用程序和 atm 我正在登录和注册功能。我决定创建一个表格视图,其中包含文本字段,以便用户可以注册。但是每次我在文本字段中输入内容并向下滚动时,文本字段都会被清除,但是为什么呢?
另外,当我点击一个按钮时,如何将这些数据添加到我的数据库中?因为我无法从那里到达它。有输入吗?
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "signUpCell", for: indexPath) as! SignUpTableViewCell
cell.txtfield.delegate = self
cell.textOfField.text = textNames[indexPath.section][indexPath.row]
cell.txtfield.text = textFields[indexPath.section][indexPath.row]
@IBAction func signUpButtonTapped(_ sender: Any)
{
let authentication = Auth.auth().currentUser?.uid
//I know how to add it to the database, but how can I retrieve the tableview data here?
}
解决方案
单元格出队需要更新数据源数组,这在里面cellForRowAt
cell.textField.addTarget(self, action: #selector(textFieldDidChange(_:)), for: .editingChanged)
cell.textField.indexPath = indexPath
和
@objc func textFieldDidChange(_ textField: CustomTexf) {
let index = textField.indexPath
textFields[index.section][index.row] = textField.text!
}
创建此类并将其分配给文本字段
class CustomTexf : UITextField {
var indexPath:IndexPath!
}
推荐阅读
- curl - curl cron 进程有时无法完成(随机)-Azure Linux
- git - 哪个工作流程会导致 Git 中的“由他们添加”冲突?
- javascript - 如何使用刷新令牌刷新不和谐 Oauth2 访问令牌?
- docker - dockerfile中的phpmyadmin错误如何解决?
- python - 如何在 Python 中更改列表中的项目?
- c# - Unity如何正确获取字符宽度
- python - 如果我们将整数作为输入,为什么 set 中的 pop 函数会弹出第一个元素?
- firebase - 通过 cmd $flutter pub add firebase_auth 添加 firesbase 时,文件 generated_plugin_registrant.dart 显示错误(红色)
- python - 创建唯一组名的请求
- ssas - 在表格立方体模型的 MDX 查询中使用计算成员中的日期范围