swift - 快速获取表格视图单元格值为零
问题描述
我有 3 个部分的表格视图。每个部分都有一行。在我的模拟器屏幕中,仅显示 2 个部分。如果我滚动表格视图,将显示第三个单元格。有一个保存按钮,通过单击它我将数据传递给另一个视图控制器。如果我不滚动表格视图并单击保存按钮,则第三部分的单元格为零。
我的代码是:-
let indexPath = IndexPath(row: 0, section: 0)
let indexPath1 = IndexPath(row: 0, section: 1)
let indexPath2 = IndexPath(row: 0, section: 2)
let cell1 = tableView.cellForRow(at: indexPath) as? PatientInformationTableViewCell
let cell2 = tableView.cellForRow(at: indexPath1) as? PatientAdressTableViewCell
let cell3 = tableView.cellForRow(at: indexPath2) as? OtherInfoTableViewCell
guard let name = nameTextField.text,
let id = cell1.patientTextField.text,
let dob = cell1.dobTextField.text,
let street = cell1.streetAdressTextField.text,
let city = cell2.cityTextField.text,
let state = cell2.stateTextField.text,
let zip = cell2.zipTextField.text,
let country = cell2.CountryTextField.text,
let practioner = cell3.practionerTextField.text,
let lcode = cell3.lcodeTextField.text,
let qty = cell3.qtyTextField.text,
let prescription = cell3.PrescriptionTextView.text,
let klLevel = cell3.kLevelTextField.text,
let deviceType = cell3.deviceTypeTextField.text,
let guardian = cell3.guardianTextField.text,
let relationship = cell3.relationshipwithPatient.text
else {
return
}
let patient = PatientInformationModel(name: name, id: id, dob: dob, streetAdress: street, city: city, state: state, zip: zip, country: country, klevel: klLevel, deviceType: deviceType, visitType: "visitType", deliveryLocation: "deliveryLocation", lCode: lcode, qty: qty, descripePrescription: prescription, practioner: practioner, guardian: guardian, relationship: relationship)
let encoder = JSONEncoder()
if let encoded = try? encoder.encode(patient) {
let defaults = UserDefaults.standard
defaults.set(encoded, forKey: "SavedPerson")
}
if let storyBoard = UIStoryboard(name: "Pdf", bundle: nil) as? UIStoryboard{
captureSignature { (sign) in
signatureImage = sign?.image
print("signature image is \(signatureImage)")
}
let PatientListViewController = storyBoard.instantiateViewController(identifier: "GeneratePdfViewController") as? GeneratePdfViewController
PatientListViewController?.signatureImage = signatureImage
self.navigationController?.pushViewController(PatientListViewController!, animated: true)
}
在上面的代码中,如果我点击保存按钮而不滚动到底部,我得到的 cell3 值为零。有什么解决办法吗?请帮我。
解决方案
推荐阅读
- r - 整洁的 ggplot-esque 方式来绘制在每年开始时重新设置的时间序列
- django-rest-framework - Serializers 类的 update() 方法和 UpdateAPIView 有什么不同?
- entity-framework - 插入后缺少 EF Core 5 外键
- google-apps-script - 自动将值从一个列复制到另一个列并使其固定
- pine-script - 目标订单未完成
- c# - 在 Unity C# 中使用复选框和 playerprefs 切换布尔值
- plugins - 通过 Jira 的 ScopeMaster 插件的 API 文档
- java - Spring Boot REST 请求 JSON 相同的参数名称
- aws-lambda - 如何以安全的方式在 template.yaml 中添加环境变量?
- python - Django- CSS 不适用于其他页面,例如标题标签