Resolved Wrong segue identifier being used

Discussion in 'iOS Programming' started by moonman239, Jul 30, 2014.

  1. moonman239, Jul 30, 2014
    Last edited: Jul 30, 2014

    moonman239 macrumors 68000

    Mar 27, 2009
    In one of the apps I'm building is a view controller. This view controller has segues, each of which is supposed to be triggered by the tap of a given table view cell.

    As you can tell from the code I'll post below, the app is supposed to use a switch-case statement to decide which segue the view controller is to perform. The code works for the first cell in the first section, but not for the second cell in the section. The app knows that the row number of the second cell is 1, but seems to pretend that the number is 2.

    Here's the code:

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
        NSString *segueIdentifier;
        NSInteger row = [indexPath row];
        switch (row) {
            case 0:
                segueIdentifier = @"segue1";
            case 1:
                segueIdentifier = @"segue2";
            case 2:
                segueIdentifier = @"segue3";
        [self performSegueWithIdentifier:segueIdentifier sender:[NSNumber numberWithInteger:[indexPath section]]];
  2. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    The problem lies in your breaks, or lack thereof.
  3. moonman239 thread starter macrumors 68000

    Mar 27, 2009
    The reason I had a problem is that I left out a break statement after the part where the value of segueIdentifier is set to "segue2."

    EDIT: You beat me to it, demo!

Share This Page