我需要检查每个部分。
我在本节的标题中有问题。并且在tableview的cellfor行中的选项。选择单元格后,我有Submit按钮。因此在单击Submit按钮时,它应该验证我是否已从每个单元格中选择一个单元格部分。如何做。
为此,我当前的代码如下:-
let totalSections = questionViewModel.numberOfSections()
for section in 0..<totalSections {
let totalRows = questionViewModel.numberOfRowsIn(section:section)
for row in 0..<totalRows{
let cell = self.tableview.cellForRow(at: NSIndexPath(row: row, section: section) as IndexPath)
// self.tableview.cellForRow(at: IndexPath(row: row, section: section))
print("Section: \(section) Row: \(row)")
let model = questionViewModel.datafordisplay(atindex: IndexPath(row: row, section: section))
print(model.isSelected)
// questionViewModel.search(indexPath: IndexPath(row: row, section: section))
questionViewModel.search(indexPath: IndexPath(row: row, section: section))
print(questionViewModel.OptionListArray)
if (questionViewModel.OptionListArray?.count)!>=1{
print("success")
continue
}
else{
let questionModel = questionViewModel.titleForHeaderInSection(atsection: section)
print(questionModel.question)
let controller = UIAlertController(title: "Please Select any option from question", message:(questionModel.question), preferredStyle: .alert)
// Create the actions
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default) {
UIAlertAction in
NSLog("OK Pressed")
self.viewDidLoad()
}
controller.addAction(okAction)
// controller.addAction(cancel)
self.present(controller, animated: true, completion: nil)
// self.viewDidLoad()
}
}
}
我正在mvvm中进行操作,因此我的viewmodel如下:-
var OptionListArray:Array<NH_OptionsModel>? = []
func search(indexPath: IndexPath)-> Bool {
OptionListArray = (datasourceModel.dataListArray?[indexPath.section].optionsModelArray.filter{($0.isSelected! == true)})!
print(OptionListArray)
return true
}
所以我需要以下输出。 如果我从每个部分中选择了一个单元格,则进行按钮操作。否则,如果未选择任何一个单元格,则显示针对特定部分的选项选择提示。
在这里我已经将isSelected设置为模型的假初始值。在选择单元格时,它变为true。
为此,我筛选了每个部分是否有任何模型是否具有isSelected = true。如果没有显示警告,请选择任何选项以阻止部分编号。如何实现