首页 > 解决方案 > 快速获取表格视图单元格值为零

问题描述

在此图像中显示了两个部分,滚动后将显示第三个部分我有 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 值为零。有什么解决办法吗?请帮我。

标签: swifttableview

解决方案


推荐阅读