11

I am having hard time getting performSegueWithIdentifier to work. I keep getting

"Receiver (<UINavigationController: 0x1e59a9d0>) has no segue with
 identifier 'identA'"

What I did is that:

  1. Step: created a single view application and added a label - "View controller A" to the view controller.
  2. Step: Dragged and dropped another View Controller and added a label - "View controller B" to the new view controller.
  3. Step: Chose view controller A and performed Editor->embed in->navigation controller
  4. Step: wired View controller A to View controller B with push segue with Identifier "identA" Like this: wiring the seque

  5. Step: added a call to performSegueWithIdentifier onView controller A's ViewDidLoad. Like this:


- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.navigationController performSegueWithIdentifier:@"identA" sender:self];
    // Do any additional setup after loading the view, typically from a nib.
}

What have I done wrong???

stefanB
  • 77,323
  • 27
  • 116
  • 141
Yony
  • 680
  • 1
  • 9
  • 20

3 Answers3

26

You are calling performSegueWithIdentifier:sender: on self.navigationController but you setup the segue on View controller A:

wired View controller A to View controller B with push segue with Identifier "identA"

Try replacing:

[self.navigationController performSegueWithIdentifier:@"identA" sender:self];

with

[self performSegueWithIdentifier:@"identA" sender:self];
stefanB
  • 77,323
  • 27
  • 116
  • 141
4

Just another suggestion (which saved me today)...

I've written many iPad & iPhone apps before, using Master-Detail pages, Navigation Controllers, etc, but today, I was stumped, as my simple two-screen iPhone app in XCode 5.1 refused to let me segue from one screen to another, within a UINavigationController.

It's another of those insane XCode bugs which made no sense. I could even create a new XCode project, and there, the same segue would work perfectly.

    [self performSegueWithIdentifier:@"segueTest" sender:nil];

Eventually, I found out the cause.

I had created a blank project in XCode, manually added a Storyboard to my project, but, I'd missed a step.

When you add a Storyboard yourself, you also need to go into your .plist file, and manually add a line telling your app the name of your main storyboard.

enter image description here

If you don't do this, strangely, your app will build successfully, it will run, you'll probably get your first screen to be displayed successfully... but then things (like finding segue names) will start to go wrong.

(Sigh.)

I hope this helps other XCode victims.

I need a beer...

Mike Gledhill
  • 27,846
  • 7
  • 149
  • 159
0

Ok. Bit of a particular situation here, but in my situation I had a UISplitViewController set up in a new project. I wanted to perform a segue in the detail view controller after pressing a cell in the master table view. So in didSelectRowAtIndexPath: of the master table I performed

[[NSNotificationCenter defaultCenter]postNotificationName:@"userDetails"
                                                           object:nil];

and in the detail view in viewDidLoad: I added the observer and the instance method

[[NSNotificationCenter defaultCenter]addObserver:self
                                        selector:@selector(userDetailsShow)
                                            name:@"userDetails"
                                          object:nil];
-(void)userDetailsShow{
    [self performSegueWithIdentifier:@"userDetails" sender:nil];
}

When pressing the cell in the master view it would fire the method but do nothing. It turned out the problem was this: enter image description here

I had left the default segue between the master table view cell and detail navigation controller active. In this case I didn't need it, so was able to delete it. Once deleting it it worked perfectly, as it should.
Hopefully I can now put this hair back in...

mylogon
  • 2,772
  • 2
  • 28
  • 42