Of course! Define all your segues on the storyboard, ctrl-dragging from the ViewController table (and not the row, TableViewController itself) for the next view. Give them IDs so you know who to call. When all your segues are defined visually, go to the code. In your tableView delegate, in didSelectRowAtIndexPath , just call the segment you want by checking indexPath.row :
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { switch (indexPath.row) { case 0: [self performSegueWithIdentifier:@"Segue0" sender:self]; break; case 1: [self performSegueWithIdentifier:@"Segue1" sender:self]; break; [...] default: break; } }
Thus, a segue with the identifier "Segue0" will be started when the user selects the first row, etc.
You can also add the line: [tableView deselectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1] animated:YES]; at the beginning didSelectRowAtIndexPath so that the row does not remain selected after the user touched it!
Edit: this works for both static and dynamic cells! Be careful to ctrl-drag your segue from tableViewController, not from a cell!
rdurand
source share