Search code examples
iphoneiosuitableviewios6uistoryboardsegue

Tableview to itself and to Viewcontroller [Multiple segues]


I have a UITableView with many cells and depends on the cell's content it suppused to go to the same UITableView with new cells or to a UIViewController. I can do this but not at the same time, is it possible to do it?

I thought in a prepareForSegue method like this one:

 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
 {
      NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

     if ([[segue identifier] isEqualToString:@"NextLevel"]) {
         [segue.destinationViewController setActualNodo:[actualNodo getSonAtIndex:indexPath.row]];
     } else if ([[segue identifier] isEqualToString:@"Service"]) {
         [segue.destinationViewController setServiceName: whatever]
     }

 }

The problem is in the Storyboard that I can't ctrl+drag two segues from the same cell. Thanks.


Solution

  • No, that's not possible for segues in IB. You can check for different segues that all originate from your controller the way you show in prepareForSegue, but a UI element can only have one segue connected to it.

    To do what you want, you should make a segue from the table view controller itself to the new controller. Then, in didSelectRowAtIndexPath, use whatever logic you want to decide whether to go to this new controller (with [self performSegueWithIdentifier:sender:]), or to update the table view with new cells.