我用过tableview(摸索)。 对于每个部分,我需要从表格视图的每个部分中选择一个单元格。
选择单元格后,我滚动表格视图,然后缺少所选单元格。如何更正... 这是我的代码:-
let questionsModel = questionViewModel.titleForHeaderInSection(atsection:indexPath.section)
print(questionsModel.buttontype)
questionViewModel.button = questionsModel.buttontype
cell.setOptions(Options1: questionViewModel.datafordisplay(atindex: indexPath))
print("Section \(indexPath.section), Row : \(indexPath.row)")
if questionViewModel.button == "2"{
self.selected = 1
cell?.imagebutton.setImage(UIImage(named: "radio_uncheck.png"), for: .normal)
cell.setOptions(Options1: questionViewModel.datafordisplay(atindex: indexPath))
questionViewModel.imagename = "2"
}
else if questionViewModel.button == "1"{
cell?.imagebutton.setImage(UIImage(named: "checkbox_uncheck.png"), for: .normal)
}
else if questionViewModel.button == "3"{
self.selected = 1
/////smileys/////////.................
// cell?.imagebutton.setImage(UIImage(named: "radio_uncheck.png"), for: .normal)
cell.setSmileyRating(Options:questionViewModel.datafordisplay(atindex: indexPath))
questionViewModel.imagename = "3"
}
else if questionViewModel.button == "4"{
self.selected = 1
// print(cell.floatRatingView.rating)
// cell?.imagebutton.setImage(UIImage(named: ""), for: .normal)
cell.setStarRating(Options:questionViewModel.datafordisplay(atindex: indexPath))
questionViewModel.imagename = "4"
}
else if questionViewModel.button == "5"{
self.selected = 1
cell.setOtherOptions(Options:questionViewModel.datafordisplay(atindex: indexPath))
questionViewModel.imagename = "2"
}
if (cell.question.text == "rating_star") {
cell.RatingaddCell = {[weak self] in
if let i = self?.tableview.indexPath(for: $0) {
// print(i)
print("the Selected button is \(cell.tagSelected ?? "")")
print(i)
cell.setStarRating(Options:(self?.questionViewModel.datafordisplay(atindex: indexPath))!)
print(cell.floatRatingView.rating)
let model = self?.questionViewModel.datafordisplay(atindex: indexPath)
print(model?.values ?? "")
print(cell.floatRatingView.rating)
print("Section \(indexPath.section), Row : \(indexPath.row)")
let indexPath = IndexPath(row: indexPath.row, section:indexPath.section);
self?.tableview.selectRow(at: indexPath, animated: false, scrollPosition: UITableViewScrollPosition.none)
self?.tableView((self?.tableview)!, didSelectRowAt: indexPath)
}
print(cell.texttype.text ?? "")
}
}
if (cell.question.text == "text") {
print("text")
cell.textadd = {[weak self] in
if let i = self?.tableview.indexPath(for: $0) {
print("the selected text\(cell.textname ?? "")")
print(i)
print("the Selected button is \(cell.textname ?? "")")
print(i)
cell.setText(Options:(self?.questionViewModel.datafordisplay(atindex: indexPath))!)
let model = self?.questionViewModel.datafordisplay(atindex: indexPath)
print(model?.values ?? "")
print("Section \(indexPath.section), Row : \(indexPath.row)")
let indexPath = IndexPath(row: indexPath.row, section:indexPath.section);
self?.tableview.selectRow(at: indexPath, animated: false, scrollPosition: UITableViewScrollPosition.none)
self?.tableView((self?.tableview)!, didSelectRowAt: indexPath)
}
print(cell.texttype.text ?? "")
self?.u = 1
}
}
print(cell.question.text)
if (cell.question.text == "smiley"){
cell.SmileyPoorCell = {[weak self] in
if let i = self?.tableview.indexPath(for: $0) {
print("the Selected button is \(cell.tagSelected)")
print(i)
cell.setDataSmileyRating(Options:(self?.questionViewModel.datafordisplay(atindex: indexPath))!)
let model = self?.questionViewModel.datafordisplay(atindex: indexPath)
print(model?.values ?? "")
print("Section \(indexPath.section), Row : \(indexPath.row)")
let indexPath = IndexPath(row: indexPath.row, section:indexPath.section);
self?.tableview.selectRow(at: indexPath, animated: false, scrollPosition: UITableViewScrollPosition.none)
self?.tableView((self?.tableview)!, didSelectRowAt: indexPath)
self?.u = 1
}
}
cell.SmileyaddCell = {[weak self] in
if let i = self?.tableview.indexPath(for: $0) {
print("the Selected button is \(cell.tagSelected)")
print(i)
cell.setDataSmileyRating(Options:(self?.questionViewModel.datafordisplay(atindex: indexPath))!)
let model = self?.questionViewModel.datafordisplay(atindex: indexPath)
print(model?.values ?? "")
print("Section \(indexPath.section), Row : \(indexPath.row)")
let indexPath = IndexPath(row: indexPath.row, section:indexPath.section);
self?.tableview.selectRow(at: indexPath, animated: false, scrollPosition: UITableViewScrollPosition.none)
self?.tableView((self?.tableview)!, didSelectRowAt: indexPath)
self?.u = 1
}
}
cell.SmileyNothappyCell = {[weak self] in
if let i = self?.tableview.indexPath(for: $0) {
print("the Selected button is \(cell.tagSelected)")
print(i)
cell.setDataSmileyRating(Options:(self?.questionViewModel.datafordisplay(atindex: indexPath))!)
let model = self?.questionViewModel.datafordisplay(atindex: indexPath)
print(model?.values ?? "")
print("Section \(indexPath.section), Row : \(indexPath.row)")
let indexPath = IndexPath(row: indexPath.row, section:indexPath.section);
self?.tableview.selectRow(at: indexPath, animated: false, scrollPosition: UITableViewScrollPosition.none)
self?.tableView((self?.tableview)!, didSelectRowAt: indexPath)
self?.u = 1
}
}
cell.SmileyhappyCell = {[weak self] in
if let i = self?.tableview.indexPath(for: $0) {
print("the Selected button is \(cell.tagSelected)")
print(i)
cell.setDataSmileyRating(Options:(self?.questionViewModel.datafordisplay(atindex: indexPath))!)
let model = self?.questionViewModel.datafordisplay(atindex: indexPath)
print(model?.values ?? "")
print("Section \(indexPath.section), Row : \(indexPath.row)")
let indexPath = IndexPath(row: indexPath.row, section:indexPath.section);
self?.tableview.selectRow(at: indexPath, animated: false, scrollPosition: UITableViewScrollPosition.none)
self?.tableView((self?.tableview)!, didSelectRowAt: indexPath)
self?.u = 1
}
}
cell.SmileySohappyCell = {[weak self] in
if let i = self?.tableview.indexPath(for: $0) {
print("the Selected button is \(cell.tagSelected)")
print(i)
cell.setDataSmileyRating(Options:(self?.questionViewModel.datafordisplay(atindex: indexPath))!)
let model = self?.questionViewModel.datafordisplay(atindex: indexPath)
print(model?.values ?? "")
print("Section \(indexPath.section), Row : \(indexPath.row)")
let indexPath = IndexPath(row: indexPath.row, section:indexPath.section);
self?.tableview.selectRow(at: indexPath, animated: false, scrollPosition: UITableViewScrollPosition.none)
self?.tableView((self?.tableview)!, didSelectRowAt: indexPath)
self?.u = 1
}
}
cell.SmileySohappyCell = {[weak self] in
if let i = self?.tableview.indexPath(for: $0) {
print("the Selected button is \(cell.tagSelected)")
print(i)
cell.setDataSmileyRating(Options:(self?.questionViewModel.datafordisplay(atindex: indexPath))!)
let model = self?.questionViewModel.datafordisplay(atindex: indexPath)
print(model?.values ?? "")
print("Section \(indexPath.section), Row : \(indexPath.row)")
let indexPath = IndexPath(row: indexPath.row, section:indexPath.section);
self?.tableview.selectRow(at: indexPath, animated: false, scrollPosition: UITableViewScrollPosition.none)
self?.tableView((self?.tableview)!, didSelectRowAt: indexPath)
self?.u = 1
}
}
}
return cell
如何使选定的单元格留在那里?