ios - 如何在动态 UITableView xcode 项目中更改单元格中的数据?
问题描述
我有一个具有不同单元格的动态原型表视图,我正在将单元格添加到表视图中,并且我想更改它们的内容。我找到的所有教程都是针对只有一种类型的单元格的表格视图,但我有 8 种不同的类型。我将如何更改它们的内容(即文本字段等)以及如何将它们的操作返回到主 tableview 控制器以执行一些业务逻辑?(即按下按钮等)
我所做的是:
我为每种单元格类型创建了一个服装类,并将它们连接到 customClass、类字段下。
我附加了这些类的文本字段等、操作和引用。
这是我的 cellAtRow 函数,我假设我会以某种方式在此函数中更改它?或从这里参考课程?
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { print ("indexPath: ", indexPath) print ("indexPath: ", indexPath[0]) print ("-------") if (sectionsData[indexPath[0]] == "header") { let cell = tableView.dequeueReusableCell(withIdentifier: "headerCell", for: indexPath) return cell } else if (sectionsData[indexPath[0]] == "description") { let cell = tableView.dequeueReusableCell(withIdentifier: "headerInfoCell", for: indexPath) return cell } else if (sectionsData[indexPath[0]] == "diagnoses") { let cell = tableView.dequeueReusableCell(withIdentifier: "diagnosisCell", for: indexPath) return cell } else if (sectionsData[indexPath[0]] == "perscription") { let cell = tableView.dequeueReusableCell(withIdentifier: "perscriptionCell", for: indexPath) return cell } else if (sectionsData[indexPath[0]] == "notes") { let cell = tableView.dequeueReusableCell(withIdentifier: "notesCell", for: indexPath) return cell } else if (sectionsData[indexPath[0]] == "addFaxHeadline") { let cell = tableView.dequeueReusableCell(withIdentifier: "addFaxCell", for: indexPath) return cell } else if (sectionsData[indexPath[0]] == "addFax") { let cell = tableView.dequeueReusableCell(withIdentifier: "emailNameCell", for: indexPath) return cell } else if (sectionsData[indexPath[0]] == "addEmailHeadline") { let cell = tableView.dequeueReusableCell(withIdentifier: "addEmailCell", for: indexPath) return cell } else if (sectionsData[indexPath[0]] == "addEmails") { let cell = tableView.dequeueReusableCell(withIdentifier: "emailNameCell", for: indexPath) return cell } else if (sectionsData[indexPath[0]] == "givePermissionHeadline") { let cell = tableView.dequeueReusableCell(withIdentifier: "permissionCell", for: indexPath) return cell } else if (sectionsData[indexPath[0]] == "select answer") { let cell = tableView.dequeueReusableCell(withIdentifier: "selectAnswerCell", for: indexPath) return cell }
解决方案
你需要使用
let cell = tableView.dequeueReusableCell(withIdentifier: "headerCell", for: indexPath) as! HeaderTableViewCell
cell.yourTextField.text
例如打电话
推荐阅读
- string - 找到满足特定条件的最大长度子串
- keras - (TalosReturnError) Talos 确保输入模型返回 'out, model' model.fit()
- python-3.x - 定义我的 Keras 模型时出错:“AttributeError: 'NoneType' object has no attribute '_inbound_nodes'”
- linux - 将操作系统命令输出保持在一行
- c++ - Arduino 如何使用 ESP2668 创建 wifi 接入点?
- pyqt5 - 如何检测点击窗口的标题栏?
- spring - 从 spring boot rest 控制器自动生成 typescript api
- java - 为什么我会收到任何 java 代码的“错误:无法找到或加载主类”?
- azure - 物联网设备以遥测和双胞胎的形式发送信息。then which has to be 和有什么不一样?
- python - 熊猫填充的设定值