Reputation: 123
I have multiple table view cells and I want each of them to preform a specific segue. I don't know how I would do that
My first cell say first and my second cell name is second.
I have tried dragging from each cell and making a show segue in my mainstoryboard. But nothing happens when I select the cells. Do I have to write code or what not sure. I know I could preform segue with identifier but I don't know what the code for that has to be. I tried this code:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.performSegueWithIdentifier("showDetails", sender: tableView)
}
But I can't seem to be able to do that for each of my cells.
All my code is in swift.
Thanks so much.
Upvotes: 0
Views: 66
Reputation: 38833
If you want to have specific segues for specific cells you could do a check on which row is clicked in didSelectRowAtIndexPath
and then perform the segue
. Like this (the if-statements
are just examples):
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if (indexPath.row == 0){
self.performSegueWithIdentifier("showDetails", sender: tableView)
}
else if (indexPath.row >= 1 && indexPath.row <= 10){
self.performSegueWithIdentifier("showAnother", sender: tableView)
}
else{
self.performSegueWithIdentifier("showTheLast", sender: tableView)
}
}
Upvotes: 2