1
votes

I have an app created from Xcode 4.5's boilerplate Master-Detail Application with CoreData, StoryBoards and ARC turned-on that is not calling prepareForSegue. CoreData isn't currently being used, but it will be to cache XML responses. performSegueWithIdentifier works, but prepareForSegue isn't and I'm having troubles passing/access data from the MasterViewController to/in the detailViewController created by performSegueWithIdentifier.

My basic set-up is similar to what's discussed in the thread: Storyboards and UISplitViewControllers. There's an image of a storyboard on page three that's very similar to my set-up (I don't have enough rep to post images).

In a nutshell:

  1. I create a standard splitView arrangement
  2. The MasterViewController builds the main table
  3. Each cell corresponds to a URL that returns XML data that determines what's in the detailView
  4. The fetched XML is parsed using a NSXMLParser operation/class
  5. The fetched XML determines which detail view is needed and the MasterViewController calls the appropriate 'replace' segue (via performSegueWithIdentifier) to kick-off the corresponding detailViewController to display the fetched XML

The problem that I'm having is that prepareForSegue isn't being called, so I can't pass the fetched XML to the detailViewController.

What I need is one of the following:

  • prepareForSegue to be executed
  • a way to know segue.destinationViewController inside handleLoadedResponse:notif
  • a way to get access to the "currentResponse" variable in the MasterViewController from inside the viewDidLoad method of the detailViewControllers
  • a way to find the MasterViewController via its StoryBoardID

What I've tried:

  • Putting NSLog() statements in each viewController's prepareForSegue -- none of them are called
  • Digging through the self.parentViewController chain in the detailViewController to find the MasterViewController that called performSegueWithIdentifier -- I can't find the class variable I'm looking for
  • Read pretty much every "prepareForSegue not called" post I could find -- They all seem due to some coding/storyboard error that I don't see in my code/storyboard

Could the problem be that I'm calling:

[self.navigationController performSegueWithIdentifier:@"theDesiredSegue" sender:self];

from inside the handleLoadedResponse:notif call-back and the app is trying to call prepareForSegue in my parsing object?

TIA

Ray

1

1 Answers

2
votes

Well, chalk this up to staring at the code too long and/or newbie-ness.

After triple-checking everything that I though was obvious, I thought the only thing left was that the segue code didn't behave correctly inside the NSXMLParser call-back, so I switched the handleLoadedResponse:notif routine to store the parsed data and send-out notifications.

While debugging those changes, I realized that my segues were attached to the wrong object. They were actually attached to the navigationController and not my viewController. Visually, things looked like the story board on page three of RWForums: Storyboards and UISplitViewControllers, but they really weren't. The end result being that even though it seemed like my code was calling performSegueWithIdentifier and that it's prepareForSegue method should have been called, it was actually calling the navigationController's segue, so the navigationController's inherited prepareForSegue was being called.

Recommendation: Make sure you re-re-re-check all the connections in the StoryBoard Editor with the Document Outline open.

Ray