performSegueWithIdentifier vs instantiateViewControllerWithIdentifier

31,846

Try this:

  1. Use the first code block and not the second.
  2. In storyboard control drag from the cell to the other view controller. Note that a segue is created.
  3. Click on the segue. Use the attributes inspector to give the segue and identifier "theOtherIdentifier" (lower case "t" recommended). Also select a segue style of "push" assuming you are using a navigation controller.
  4. Storyboard will instantiate the other view controller. Be sure you are not doing this in your code.
Share:
31,846
Morpheu5
Author by

Morpheu5

Oompa Loompa of (computer) science, graphic designer, wannabe rockstar.

Updated on March 02, 2020

Comments

  • Morpheu5
    Morpheu5 over 4 years

    I don't seem to get this SIGABRT I keep getting. I have this storyboard iOS application, and in the storyboard I have a UITableViewController. Now, I can take a cell of the TVC and make it push the "segue" view controller, but what if I needed to stop the "segue" action on certain conditions? Apparently you can't, since the prepareForSegue:sender: method doesn't allow for it, and it seems to be the only callback that gets called when a transition is about to get performed.

    So I guessed I could go into the tableView:didSelectRowAtIndexPath: and perform the segue programmatically. Suboptimal, but still…

    Well, it turns out I guessed wrong. Or at least, I'm doing something wrong. The most obvious way to do it would be

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        [self performSegueWithIdentifier:@"TheOtherIdentifier" sender:self];
    }
    

    but the whole app crashes with a SIGABRT, which does not give any useful information (and yes, I'm sure it's that line that makes the app crash, I checked with the debugger :) Moreover, the VC I'm trying to load has the identifier correctly set, because the following code

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"TheOtherIdentifier"];
        [self.navigationController pushViewController:vc animated:YES];
    }
    

    "works". Quotation marks indicate that this is clearly not the way such a transition should be performed.

    Now: ideas?