У меня есть несколько вопросов и ответов
вопросов в одном массиве и ответов в одном массиве.
Я хочу показать, когда пользователь выбирает вопрос, показать ответ снова, выбрать закрыть ответ.
Я пишу следующий код, но когда один ответ остается открытым, все закрыто, моя логика обратна любой помощи PLZ мне.
здесь я создал одну глобальную переменную с именем selectedindex
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "DonationTableViewCell", for: indexPath)as!
DonationTableViewCell
cell.questioncell.text = questnArr[indexPath.row]
if indexPath.row == selectedindex
{
cell.answerlbl.text = answersarr[indexPath.row]
cell.questioncell.textColor = UIColor.disSatifyclr
cell.questionimg.image = #imageLiteral(resourceName: "Drop down top icon")
}else{
cell.answerlbl.text = ""
cell.questioncell.textColor = UIColor.textmaincolor
cell.questionimg.image = #imageLiteral(resourceName: "Drop down")
}
tableviewheight.constant = tableview.contentSize.height
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
selectedindex = indexPath.row
tableView.reloadData()
}