Pergunta

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!

Foi útil?

Solução

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;
    }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top