This may be very rookie but...
I've set a segue between two ViewControllers
in my Storyboard
, with the identifier clickBtn
.
Now I'm calling it this way in my code:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"clickBtn"])
{
if(conditionVerified)
{
SecondViewController *controller = (SecondViewController *)segue.destinationViewController;
[controller setManagedObjectContext:self.managedObjectContext];
}
else
{
// If I enter here I get the error below
}
}
}
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'Link''
In fact I don't want to do this transition if I enter the else-statement. How to do so?
To optionally suppress a transition, implement
- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
and return YES
or NO
, depending on your condition. In your example:
- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
if ([identifier isEqualToString:@"clickBtn"]) {
return conditionVerified;
} else {
return YES;
}
}
In prepareForSegue:
it is "too late" to suppress the transition.
Rather than having the button perform the segue have it call a method like the following.
-(IBAction)mySegueButtonMethod:(id)sender
{
if(conditionVerified){
[self performSegueWithIdentifier:@"clickBtn" sender:sender];
}
else{
// do not perform segue and do other relevant actions.
}
}
The error you are seeing is because i am assuming controller is calling something that needs context manager not to be nil.
You can't really stop the segue from occurring once you are in the method prepareForSegue as it will always perform the segue at the end of the method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With