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:
- Step: created a single view application and added a label - "View controller A" to the view controller.
- Step: Dragged and dropped another View Controller and added a label - "View controller B" to the new view controller.
- Step: Chose view controller A and performed Editor->embed in->navigation controller
Step: wired View controller A to View controller B with push segue with Identifier "identA" Like this:
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???
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];
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.
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...
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:
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...