我在tableviewcell中有5个按钮,并为此采取了行动。
这意味着我在一个单元格中有5个笑脸。因此,在单击任何一个按钮时,数据都应输入到数组中。
这是我的代码:-此代码在didselect的表格视图中。
if questionViewModel.isselected == true{
print("jjj")
print((self.questionViewModel.selectedIndexPaths))
let selectedIndexPathAtCurrentSection = questionViewModel.selectedIndexPaths.filter({ $0.section == indexPath.section})
for indexPath in selectedIndexPathAtCurrentSection {
print(indexPath)
tableview.deselectRow(at: indexPath, animated: true)
if let indexOf = questionViewModel.selectedIndexPaths.index(of: indexPath) {
questionViewModel.selectedIndexPaths.remove(at: indexOf)
let cell = tableview.cellForRow(at: indexPath) as? NH_QuestionListCell
let questionModel = questionViewModel.titleForHeaderInSection(atsection: section)
print(questionModel.question)
print(questionModel.buttontype)
questionViewModel.button = questionModel.buttontype
let value: Int = questionModel.id
let string = String(describing: value)
questionViewModel.question_id = string
questionViewModel.removequestionid(removequestionid: questionViewModel.question_id!)
print("removed id:\(questionViewModel.removequestionid)")
questionViewModel.question = questionModel.question
questionViewModel.removequestion(question: questionViewModel.question!)
print("removed question:\( questionViewModel.removequestion)")
let model = questionViewModel.datafordisplay(atindex: indexPath)
print(model.isSelected)
print(questionViewModel.isselected)
if questionModel.buttontype == "3"{
cell?.SmileyAgainSelected(OptionsisSelected:questionViewModel.datafordisplay(atindex: indexPath))
}
print(cell?.floatRatingView.rating)
questionViewModel.isselected = model.isSelected!
print(questionViewModel.isselected)
print(questionViewModel.answers)
if questionModel.buttontype == "3"
{
questionViewModel.removeLast(answer:model.values!)
print(questionViewModel.answers)
}
print(questionViewModel.answers)
print("removed answer:\( questionViewModel.removeanswer)")
}
questionViewModel.selectedIndexPaths.append(indexPath)
print(questionViewModel.selectedIndexPaths)
print(indexPath)
print(indexPath.section)
print(indexPath.row)
print("final list:\(self.questionViewModel.selectedIndexPaths)")
let cell = tableview.cellForRow(at: indexPath) as? NH_QuestionListCell
let questionModel = questionViewModel.titleForHeaderInSection(atsection: section)
print(questionModel.question)
let model = questionViewModel.datafordisplay(atindex: indexPath)
//selecting the model........
print(model.isSelected)
print(questionViewModel.isselected)
if questionModel.buttontype == "3"{
cell?.SmileySelected(OptionsSelected:questionViewModel.datafordisplay(atindex: indexPath))
}
else if questionModel.buttontype == "4"{
cell?.StarSelected(OptionsSelected:questionViewModel.datafordisplay(atindex: indexPath))
}
questionViewModel.isselected = model.isSelected!
print(questionViewModel.isselected)
//selecting the questions........
questionViewModel.question = questionModel.question
questionViewModel.questionlist(answer: questionViewModel.question!)
print(questionModel.buttontype)
let value: Int = questionModel.id
let string = String(describing: value)
questionViewModel.question_id = string
questionViewModel.question(answer: questionViewModel.question_id!)
// questionViewModel.question(answer: questionViewModel.question_id!)
questionViewModel.button = questionModel.buttontype
print(model.values)
if questionModel.buttontype == "3"{
print(questionViewModel.answers)
}
else if questionModel.buttontype == "5"{
let model = questionViewModel.datafordisplay(atindex: indexPath)
if model.values == ""{
questionViewModel.removeLast(answer:model.values!)
}
print(questionViewModel.answers)
}
questionViewModel.answer(answer: model.values!)
}
else if questionViewModel.isselected == false{
let questionModel = questionViewModel.titleForHeaderInSection(atsection: section)
/////////////////////////////question...............
print(questionModel.question)
print(questionModel.buttontype)
questionViewModel.question = questionModel.question
questionViewModel.questionlist(answer: questionViewModel.question!)
print("add list questions:\(questionViewModel.questionlist)")
let cell = tableview.cellForRow(at: indexPath) as? NH_QuestionListCell
let model = questionViewModel.datafordisplay(atindex: indexPath)
// print(cell?.floatingrate)
print(model.isSelected)
print(questionViewModel.isselected)
print(questionModel.buttontype)
if questionModel.buttontype == "3"{
cell?.SmileySelected(OptionsSelected:questionViewModel.datafordisplay(atindex: indexPath))
}
questionViewModel.isselected = model.isSelected!
print(questionViewModel.isselected)
if questionModel.buttontype == "3"{
questionViewModel.Smileyanswer(answer:model.values!)
print(questionViewModel.Smileyanswers)
}
questionViewModel.answer(answer: model.values!)
print("add list answers:\(questionViewModel.answers)")
let value: Int = questionModel.id
let string = String(describing: value)
questionViewModel.question_id = string
questionViewModel.question(answer: questionViewModel.question_id!)
print("add list answers:\(questionViewModel.question)")
questionViewModel.button = questionModel.buttontype
questionViewModel.selectedIndexPaths.append(indexPath)
print(questionViewModel.selectedIndexPaths)
print(indexPath)
print(indexPath.section)
print(indexPath.row)
print("final list:\(self.questionViewModel.selectedIndexPaths)")
print(questionViewModel.button)
print("final list:\(self.questionViewModel.selectedIndexPaths)")
}
}
因此,据此,我将在Tableview中获得笑脸。因此,当我们单击第一个单元格时-i单击第一个笑脸按钮,则数据将输入如下:-
["Very good"]
接下来,我以为我需要从第一个单元格中获得第二个笑脸。所以我选择了第二个笑脸按钮,则数据如下所示。
["good"]
接下来我选择第二个单元格区域。我选择第一个选项 然后数据变为如下。
["good","very good"]
so here the value "good" is the section1 data and "very good" is the section2 data.
接下来我认为我需要更改section1的选项,因此我选择了第3个选项,因此数据应为:-
["bad","very good"]
这里的“不好”来自第1节,“非常好”来自第2节。 但是根据我的代码,我没有。如何解决问题?