{
"data":[
{
"mainquestion":"was the staff",
"items":[
{
"button_type":"2",
"question": "Gender",
"options": ["Male","Female"]
},
{
"button_type":"2",
"question": "How old are you",
"options": ["Under 18","Age 18 to 35","Age 36 to 50","Age 51 to 70","70 and above"]
}
]
}, {
"mainquestion":"Please tell the feedback",
"items":[
{
"button_type":"2",
"question": "Gender",
"options": ["Male","Female"]
},
{
"button_type":"2",
"question": "How old are you",
"options": ["Under 18","Age 18 to 35","Age 36 to 50","Age 51 to 70","70 and above"]
},
{
"button_type":"2",
"question": "How old are you",
"options": ["Under 18","Age 18 to 35","Age 36 to 50","Age 51 to 70","70 and above"]
}
]
}
]
}
这是api的数据格式。我需要在分组的tableview中列出数据。如何在tableview中实现嵌套部分。
我需要这种方式的输出。
Output:-
1.was the staff
a.Gender
i.Male
j.Female
b.How old are you
i.Under 18
j.Age 18 to 35
2.Please tell the feedback
a.Gender
i.Male
j.Female
b.How old are you
i.Under 18
j.Age 18 to 35
这是如何在表格视图中按分组列出数据的模式。
当前,我以这种方式获得代码:-
func numberOfSections(in tableView: UITableView) -> Int {
return questionViewModel.numberOfSections()
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 100
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let identifier = "HeaderCell"
var headercell: QuestionHeader! = tableView.dequeueReusableCell(withIdentifier: identifier) as? QuestionHeader
if headercell == nil {
tableView.register(UINib(nibName: "QuestionHeader", bundle: nil), forCellReuseIdentifier: identifier)
headercell = tableView.dequeueReusableCell(withIdentifier: identifier) as? QuestionHeader
}
headercell.setReviewData(reviews:questionViewModel.titleForHeaderInSection(atsection:section))
headercell.isUserInteractionEnabled = false
return headercell
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return questionViewModel.numberOfRowsIn(section: section)
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
let model = questionViewModel.titleForHeaderInSection(atsection: indexPath.section)
print(model.answerType)
print(model.answerType?.rawValue)
let c = model.answerType
return c!.cellType().getHeight()
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let model = questionViewModel.titleForHeaderInSection(atsection: indexPath.section)
print(model.answerType)
print(model.answerType?.rawValue)
let c = model.answerType
let cellClass = c?.cellType().getClass()
print(cellClass)
let cell = tableView.dequeueReusableCell(withIdentifier: (cellClass?.cellReuseIdentifier())!, for: indexPath) as! BaseCell
print(cell)
cell.selectionStyle = .none
let optionModel = questionViewModel.datafordisplay(atindex: indexPath)
cell.setOptions(Options1: optionModel)
return cell
}
这是我目前完成的代码。这里不使用嵌套部分。因此如何在表视图中实现嵌套部分。
如何列出主要问题,然后在主要问题中列出子问题,然后列出每个小节中的选项。如何以这种方式实现?