Multiple / optional segments from table cell UITableViewController

I saw this thread here, but none of the solutions clicked or worked for me. I have a UITableViewController , (call it myUITableViewController ), and the requirements are that if the user selects one of the first three rows from myUITableViewController , they will be wrapped into theFirstViewController , but if they selected any rows above three, they will be wrapped in theSecondViewController . I use storyboards that don't seem to allow multiple selections from the same cell in the table. However, I can add several segue directly from myUITableViewController , but then I struggle with the correct segue code and cannot find the right solution.

+3
source share
1 answer

The best way is not to use segue directly from IB, but instead to use it tableview:didSelectRowAtIndexPath:and manually call them from the code whenever they select a row in the table.

You should configure segues from the table view itself to the destinations, not the specific elements from the table.

Something like that:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {  
    NSString *identifierOfSegueToCall;
    if (indexPath.row < 3) {
        identifierOfSegueToCall = @"theFirstViewControllerSegueIdentifier";
    } else {
        identifierOfSegueToCall = @"theSecondViewControllerSegueIdentifier";
    }

    [self performSegueWithIdentifier:identifierOfSegueToCall sender:self];
}
+4
source

All Articles