iOS app terminates at final line of prepareForSegue code. Can't step into it

My app has two ViewControllers, HomeViewController and AddActivityViewController, with a segue from the latter to the former via a "+" button in the navbar of the HomeViewController.

The app exits upon hitting the final line in the prepareForSegue method:

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
        NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread];
    if ([[segue identifier] isEqualToString:@"addActivity"])
    {
        AddActivityViewController *aavc = (AddActivityViewController *) [segue destinationViewController];
        aavc.delegate = self;
        ListActivity *addedActivity = (ListActivity *)[ListActivity MR_createInContext:localContext];
        aavc.thisActivity = addedActivity;
    }

}

I've set a breakpoint at this line:

aavc.thisActivity = addedActivity;

But the app exits as soon as I try to step into the code, with this exception:

2014-01-30 13:02:53.011 MRExample[31029:a0b] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setThisActivity:]: unrecognized selector sent to instance 0x8d93290'*

If I comment out the offending line, the segue will execute.

I can supply any code that will help to clarify. All help or insights greatly appreciated!

Answers


It appears from the exception that aavc is embedded in a UINavigationController. Get a reference to aavc thru that first:

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread];
    if ([[segue identifier] isEqualToString:@"addActivity"])
    {
        UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
        AddActivityViewController *aavc = (AddActivityViewController *)navController.topViewController;
        aavc.delegate = self;
        ListActivity *addedActivity = (ListActivity *)[ListActivity MR_createInContext:localContext];
        aavc.thisActivity = addedActivity;
    }
}

Need Your Help

How to connect C# Visual Studio 2013 to php myadmin database

visual-studio phpmyadmin

I need a connector for C# Visual Studio to php myadmin database. I've searched about it but every time I get the connector of MYSQL. I don't need a MYSQL connector for C# VS. I need a connector for...

Increase java heap space in Tomcat - Windows 7 Client

java windows tomcat geoserver

I have Apache Tomcat installed on my Windows 7 Client machine, and am utilising geoserver.war as a deployment.