Reputation: 9140
I have project where I'm using UINavegationController between to views:
I'm using the navigation controller because I'm using modal presentation (Flip)
But my problem is I'm trying to pass NSString Object to ViewControllerB: Code:
- (IBAction)goToB:(id)sender {
[self performSegueWithIdentifier:@"goToB" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"goToB"]) {
BViewController *vc = (BViewController*)[segue destinationViewController];
vc.commigFromA = @"I'm going to B!";
}
}
But I'm getting this error:
-[UINavigationController setCommigFromA:]: unrecognized selector sent to instance 0x7ff1c4830c00
Any of you knows why or a way around this error?
I'll really appreciate your help
Upvotes: 0
Views: 90
Reputation: 12842
It's crashing because the destinationViewController
on the segue is actually a UINavigationController
, not a BViewController
, and UINavigationControllers
don't know about a property comingFromA
. You can test this theory by replacing prepareWithSegue
like this:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"goToB"]) {
UINavigationController *nvc = (UINavigationController*)[segue destinationViewController];
BViewController *vc = (BViewController*)nvc.viewControllers[0];
vc.commigFromA = @"I'm going to B!";
}
}
Upvotes: 1