2021年1月1日星期五

Tableview text input fields nil during submission if not in view

Im creating a form using a UITableview with labels on the left, and text inputs, and true/false selectors on the right. There is a button at the top to validate the data, and save it. However I found a bug, if the phone is in landscape mode and one of the fields is out of view during submission, the field not displayed crashes the app as the value of that cell is nil.

here is my code for the "Submit" button

   let cell0 = tableView.cellForRow(at: IndexPath(row: 0, section: 0)) as! CellString   let cell1 = tableView.cellForRow(at: IndexPath(row: 1, section: 0)) as! CellString          let cell2 = tableView.cellForRow(at: IndexPath(row: 2, section: 0)) as! MoreInfoUITableViewCell          let cell3 = tableView.cellForRow(at: IndexPath(row: 3, section: 0)) as! CellString          let cell4 = tableView.cellForRow(at: IndexPath(row: 4, section: 0)) as! CellString          let cell5 = tableView.cellForRow(at: IndexPath(row: 5, section: 0)) as! MoreInfoUITableViewCell          let cell6 = tableView.cellForRow(at: IndexPath(row: 6, section: 0)) as! MoreInfoUITableViewCell          let cell7 = tableView.cellForRow(at: IndexPath(row: 7, section: 0)) as! CellBool          let cell8 = tableView.cellForRow(at: IndexPath(row: 8, section: 0)) as! CellBool          let cell9 = tableView.cellForRow(at: IndexPath(row: 9, section: 0)) as! CellBool  

Below is the code to add the fields to the new object...

let newObject = Aircraft(context: context)          newAircraft.obj0 = cell0.textInput.text!          newAircraft.obj1 = cell1.textInput.text          newAircraft.obj2 = cell2.rightLabel.text          newAircraft.obj3 = cell3.textInput.text          newAircraft.obj4 = cell4.textInput.text          newAircraft.obj5 = cell5.rightLabel.text          newAircraft.obj6 = cell6.rightLabel.text          newAircraft.obj7 = cell7.trueFalseSelector.isOn          newAircraft.obj8 = cell8.trueFalseSelector.isOn          newAircraft.obj9 = cell9.trueFalseSelector.isOn  
https://stackoverflow.com/questions/65535169/tableview-text-input-fields-nil-during-submission-if-not-in-view January 02, 2021 at 09:05AM

没有评论:

发表评论