3

I know there are lots of postings about this but I have tried everything and nothing has worked. So I have tried to pass an object between two view controllers, to a DBKIngredientsViewController embedded in a navigation item. I have a push segue with the identifier "showIngredientsSegue" to the DBKIngredientsViewController. The error message I receive is:

'NSInvalidArgumentException', reason: '-[DBKIngredientsViewController topViewController]: unrecognized selector sent to instance 0x8a92450'

The view controller to which I am segueing is embedded in a navigation controller, which I think is messing it up. What's the way around this? To be clear, the DBKViewController is already embedded in a navigation controller, and the push segue pushes the DBKViewController, not the navigation controller embedding it. I have tried it different ways but none seem to work.

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if([segue.identifier isEqualToString:@"showIngredientsSegue"]){
        
        UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
        DBKIngredientsViewController *controller = (DBKIngredientsViewController *)navController.topViewController;
        controller.targetRecipe = selectedRecipe;
    }
}

IMG

Community
  • 1
  • 1
user1657563
  • 237
  • 4
  • 13

1 Answers1

2

Are you sure that segue.destinationViewController is a UINavigationController? It seems like it's just a DBKIngredientsViewController so this should work:

DBKIngredientsViewController *controller = (DBKIngredientsViewController *)segue.destinationViewController

Also if DBKViewController already has a navigation controller then you do not need a second one if you are pushing DBKIngredientsViewController. You would only need a second one if you are modally displaying DBKIngredientsViewController.

Ric
  • 8,615
  • 3
  • 17
  • 21
  • hmm, I tried that. This is the error: Warning: Attempt to present on while a presentation is in progress! – user1657563 Nov 02 '13 at 04:55
  • Then the problem is how you are presenting the view controller. How is the view controller presented? Are you dismissing a modal and pushing at the same time or pushing twice at the same time? – Ric Nov 02 '13 at 05:00
  • I guess it's two pushes? The first view controller is pushed on top of the root navigation view controller. I'm then pushing the DBKIngredientsViewController in the segue. – user1657563 Nov 02 '13 at 05:17
  • Yeah just remove the second `UINavigationController`, I've updated my answer. – Ric Nov 02 '13 at 05:18
  • I took out the second UINavigationController but now I have a new problem.. nested push animation can result in corrupted navigation bar 2013-11-02 01:32:09.549 RecipesWithCore[21666:70b] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted. – user1657563 Nov 02 '13 at 05:34
  • 1
    Is the segue happening twice for some reason? Are you calling it via the code as well maybe on cell selection? – Ric Nov 02 '13 at 05:37
  • Yes, you got it. Thanks for the help. Did not realize that I connected the segue in storyboard via the cell selection, as opposed to the view. Now it works. – user1657563 Nov 02 '13 at 05:42
  • Awesome. Just translating the errors :) I ran into a lot of these same issues when I started iOS as well. – Ric Nov 02 '13 at 05:50