Hi developers im having this trouble with expandable cells sections when using return arrayUiText[section].nombre.count on numberOfRowsInSection, only returns 1 cell and that's correct because it only have 1 number in the array, but my question is how could i return more than one because i have 3 different cells but returning is been a struggle for me as you can see my arrayUiText as multiples names in diffent arrays, i could archieve my goal just adding multiples names on 1 array, but i could only use 1 SectionHeader and that's not what i wanted to do nombre: ["dasdad dasda", "asdasdasda", "asdasdsa"] like this.
i try to numberOfRowsInSection return 3 but it collapses
i try to numberOfRowsInSection return 3 but it collapses
Code Block var arrayUiText = [ typeOfPasajeroNameLastName(isExpanded: false, pasajeroNumber: ["Pasajero 1"], pasajeroType: ["Adulto"], nombre: ["dasdad dasda"], apellido: ["asdasd asdas"], birthDate: ["24/05/1994"]), typeOfPasajeroNameLastName(isExpanded: false, pasajeroNumber: ["Pasajero 2"], pasajeroType: ["Adulto"], nombre: ["asdad"], apellido: ["asda asdasd"], birthDate: ["21/04/1994"]), typeOfPasajeroNameLastName(isExpanded: false, pasajeroNumber: ["Pasajero 3"], pasajeroType: ["Bebé"], nombre: ["asdas"], apellido: ["asdasd asdass"], birthDate: ["08/08/2018"]) ] extension PasajerosPaso2View: UITableViewDelegate, UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { if !arrayUiText[section].isExpanded{ return 0 } return arrayUiText[section].nombre.count //this returns 1 i want returning 3 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if indexPath.row == 0 { let cell = tableView.dequeueReusableCell(withIdentifier: "pasajerosData", for: indexPath) as! PasajerosPaso2Cell cell.selectionStyle = .none cell.tipoDeDatoTextField.text = arrayUiText[indexPath.section].nombre[indexPath.row] cell.tipoDeDatoTextField.delegate = self print("indexpath 0: \(arrayUiText[indexPath.section].nombre)") return cell } if indexPath.row == 1{ let cell = tableView.dequeueReusableCell(withIdentifier: "pasajerosApellidos", for: indexPath) as! PasajerosApellidosCell cell.selectionStyle = .none cell.tipoDeDatoTextField.text = arrayUiText[indexPath.section].apellido[indexPath.row] cell.tipoDeDatoTextField.delegate = self print("indexpath 1: \(arrayUiText[indexPath.section].apellido)") return cell } else { let cell2 = tableView.dequeueReusableCell(withIdentifier: "pasajerosBirthday", for: indexPath) as! PasajerosDateCell cell2.selectionStyle = .none cell2.tipoDeDatoTextField.text = arrayUiText[indexPath.section].birthDate[indexPath.row] print("indexpath 2: \(arrayUiText[indexPath.section].birthDate[indexPath.row])") return cell2 } } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return 60 } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { print(indexPath.row) } func numberOfSections(in tableView: UITableView) -> Int { return 3 } func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { let headerView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: tableView.frame.width, height: 50)) let headerCell = tableView.dequeueReusableCell(withIdentifier: "titleCelll") as! TitleCell headerView.addSubview(headerCell) headerView.backgroundColor = .white headerCell.pasajeroNumber.text = arrayUiText[section].pasajeroNumber.first headerCell.pasajeroType.text = arrayUiText[section].pasajeroType.first let tapGesture5: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleExpandClose2)) tapGesture5.numberOfTapsRequired = 1 tapGesture5.numberOfTouchesRequired = 1 headerCell.isUserInteractionEnabled = true headerCell.addGestureRecognizer(tapGesture5) headerCell.tag = section print(headerCell.tag) return headerView } func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return 50 } } @objc func handleExpandClose2(sender: UITapGestureRecognizer) { print("Trying to expand and close section...") //delegate?.cerrarLista1(self) let section = sender.view?.tag ?? 0 // we'll try to close the section first by deleting the rows var indexPaths = [IndexPath]() for row in arrayUiText[section].nombre.indices { let indexPath = IndexPath(row: row, section: section) indexPaths.append(indexPath) } let isExpanded = arrayUiText[section].isExpanded arrayUiText[section].isExpanded = !isExpanded if isExpanded { pasajerosTableView.deleteRows(at: indexPaths, with: .fade) } else { pasajerosTableView.insertRows(at: indexPaths, with: .fade) } }