I have two buttons triggering segues to two different UIViewCOntrollers, using this code:
- (IBAction)newTransButton:(UIButton *)sender
{
[self performSegueWithIdentifier:@"newTransSegue" sender:self];
}
- (IBAction)switchAccountButton:(UIButton *)sender
{
[self performSegueWithIdentifier:@"selectAccountSegue" sender:self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread];
if ([[segue identifier] isEqualToString:@"newTransSegue"])
{
UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
AddTransactionVC *atvc = (AddTransactionVC *)navController.topViewController;
atvc.delegate = self;
WMMGTransaction *addedTransaction = (WMMGTransaction *)[WMMGTransaction MR_createInContext:localContext];
addedTransaction.account = self.currentAccount.name;
atvc.thisTransaction = addedTransaction;
}
else if ([[segue identifier] isEqualToString:@"selectAccountSegue"])
{
UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
AccountSelectVC *acctSelVC = (AccountSelectVC *)navController.topViewController;
acctSelVC.delegate = self;
}
}
Activation of either button segues to the appropriate view controller, but causes this warning:
Warning: Attempt to present <UINavigationController: 0x7fb99b4dd430> on <FirstViewController: 0x7fb99b565dd0> whose view is not in the window hierarchy!
I have a Save and a Cancel Navigation bar button on each View controller. Other than as mentioned above, everything works as expected, except for the Cancel button on the View controller at newTransSegue
, which dismisses the VC, but crashes the app with this error:
EXC_BAD_ACCESS (code = 1, address = 0x7f87394af29)
Here is the delegate method I use to dismiss that VC:
-(void)addTransactionViewControllerDidCancel
{
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
I've been at this for a couple of days, and have tried deleting the segues and recreating them in storyboard, as well as doing the same for the navigation controllers. I've gone off the rails somewhere, but can't see exactly where.
I could sure use some guidance. :)