I use the actionGoal in the data model as a section:
// Table View Sections
func numberOfSections(in tableView: UITableView) -> Int {
return result?.data3.count ?? 0
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return result?.data3[section].actionGoal
// Table View
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if let result = result {
return result.data3[section].actions.count
}
return 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let action = result?.data3[indexPath.section].actions[indexPath.row]
let cell = ActionTableView.dequeueReusableCell(withIdentifier: "ActionCell", for: indexPath) as! ActionTableCell
cell.ActionTitle.text = action?.actionTitle
cell.ActionImage.image = UIImage(named: action!.actionImage)
return cell
And the I am doing the segue:
// This code is for the transfer to the next page
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
index = 0
performSegue(withIdentifier: "showDetail", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destination = segue.destination as? ActionDetailViewController {
destination.action = result?.data3[index].actions[(tableView.indexPathForSelectedRow?.row)!]