[ad_1]
I’ve 6 customized cells in my tableview. And every cells knowledge I have to examine whether or not person stuffed or not on motion of Submit button and I have to go these info to server if all of the cells data stuffed as a result of all cells are necessary to fill earlier than to ship server. If something person missed to fill, I need to throw alert to fill that cell.
However, I get cell is nil if the cell is past display.
@IBAction func submitBtnAction(_ sender: Any) {
let dictionary = self.fetchSelectedCellsInfo()
//name api right here by passing dictionary
}
func fetchSelectedCellsInfo() -> [[String: String]] {
// self.appSurveyTableview.reloadData()
if eachIndexInfo.depend > 0 {
for (index, merchandise) in eachIndexInfo.enumerated() {
let cellId = activeCells[index]
let indexPath = IndexPath.init(row:index, part: 0)
swap cellId.identifier {
case .yesNoCell:
let yesNoCell = self.appSurveyTableview.cellForRow(at: indexPath) as? YesNoTableViewCell
if let savedFlag = yesNoCell?.savedFlagValue, savedFlag.isEmpty == false {
selectedArrDictionary.append(["yesNoCell.savedFlagValue":savedFlag])
} else {
self.showBasicAlert(title: "Please present suggestions for (merchandise.query ?? "") ", message: "")
}
break
case .TextWithCheckBoxesCell:
let textWithCheckBoxCell = self.appSurveyTableview.cellForRow(at: indexPath) as? TextWithCheckBoxesTableViewCell
if let selectedOption = textWithCheckBoxCell?.selectedOption, selectedOption.isEmpty == false {
selectedArrDictionary.append(["savedFlagValue":selectedOption])
} else {
self.showBasicAlert(title: "Please present suggestions for (merchandise.query ?? "") ", message: "")
}
break
case .textWithRadioBtnsCell:
let textWithRadioBtnsCell = self.myTableview.cellForRow(at: indexPath) as? TextWithRadioButtonsTableViewCell
if let selectedOption = textWithRadioBtnsCell?.selectedOption, selectedOption.isEmpty == false {
selectedArrDictionary.append(["savedFlagValue":selectedOption])
} else {
self.showBasicAlert(title: "Please present suggestions for (merchandise.query ?? "") ", message: "")
}
break
case .ratingCell:
let ratingCell = self.myTableview.cellForRow(at: indexPath) as? RatingTableViewCell
if let labelText = ratingCell?.ratingTextLabel.textual content, labelText.isEmpty == false {
selectedArrDictionary.append(["savedFlagValue":labelText])
} else {
self.showBasicAlert(title: "Please present suggestions for (merchandise.query ?? "") ", message: "")
}
break
case .ratingWithTextBoxCell:
let ratingWithTextBoxCell = self.myTableview.cellForRow(at: indexPath) as? RatingWithTextBoxTableViewCell
if let ratingTextLabelText = ratingWithTextBoxCell?.ratingTextLabel.textual content, let textViewText = ratingWithTextBoxCell?.textView.textual content, ratingTextLabelText.isEmpty == false && textViewText.isEmpty == false{
selectedArrDictionary.append(["savedFlagValue":ratingTextLabelText])
} else {
self.showBasicAlert(title: "Please present suggestions for (merchandise.query ?? "") ", message: "")
}
break
case .appTextBoxCell:
let textWithTextBoxCell = self.myTableview.cellForRow(at: indexPath) as? TextboxTableCell
if let textViewText = textWithTextBoxCell?.textView.textual content, textViewText.isEmpty == false {
selectedArrDictionary.append(["savedFlagValue":textViewText])
} else {
self.showBasicAlert(title: "Please present suggestions for (merchandise.query ?? "") ", message: "")
}
break
case .none:
break
}
}
}
return selectedArrDictionary
}
Easy methods to entry all cells data?
Any strategies?
[ad_2]