I'm working with sections in a tableview in storyboard, where selecting a cell in the section will guide me to another screen. I have managed to do it but I feel that I use too much code and must see a better way to develop it, I have seen similar publications where they try to do the same, here I found this answer
Will the number of sections and items in the section change? If not, creating static cells and hooking up a segue to each cell to a different destination can be done with no code (all in Interface Builder).
is exactly what happens in my case and I would be interested to do of this form. I have fixed data that will not change. Now I try to develop this function in the best way possible and not as I currently have it. I must emphasize that I am a beginner in the development with swift.
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch indexPath.section {
case 0:
switch indexPath.row{
case 0:
self.performSegue(withIdentifier: "goToCreateAccountViewController", sender: nil)
break
case 1:
break
case 2:
break
default:
break
}
break
case 1:
switch indexPath.row{
case 0:
break
case 1:
break
case 2:
break
default:
break
}
break
case 2:
break
case 3:
break
default:
break
}
}
cellForRow :
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell : UITableViewCell = UITableViewCell(style: UITableViewCell.CellStyle.subtitle, reuseIdentifier: "item_option")
cell.textLabel?.text = options[indexPath.section][indexPath.row]
cell.imageView?.image = UIImage(named: "icon-myprofile")
cell.textLabel?.font = cell.textLabel?.font.withSize(14)
return cell
}