Search code examples
iphoneiosuitableviewios5storyboard

How to "cancel" a UIStoryBoardSegue


Does anyone know how to "stop" a segue transition conditionally:

My table view cells represent products which can be viewed in a drill-down "detail" view... or cannot! (It depends on a couple of things)

Now my App considers all products "unlocked":

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
    ListaProdottiController *prodottiViewController = [segue destinationViewController];
    prodottiViewController.blocco = [self.fetchedResultsController objectAtIndexPath:selectedRowIndex];
}

How can I cancel the row selection => drilldown, at this point?


Solution

  • If you are targeting iOS 6 or greater, then my knowledge of the cleanest way to do this is the following:

    -(BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
    {
        if([identifier isEqualToString:@"show"])
        {
            NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
            Blocco *blocco = [self.fetchedResultsController objectAtIndexPath:selectedRowIndex];
            return [blocco meetRequiredConditions];
        }
        return YES;
    }
    

    Where there is a method

    -(BOOL) meetsRequiredConditions;
    

    Defined on your Blocco class returns YES if the "couple of things" which permit a drill-down are valid.