I have quite a complicated setup in my app that involves an embedded UISplitViewController
which feeds a bunch of UIViewControllers
.
What I am needing to do is pass an NSManagedObject
through the embedded UISplitViewController
so I can access it in my separate detail' UIViewControllers
.
I have attached an image of my storyboard with some awesome annotations....
This is my prepareForSegue function at the minute, this is in the View Controller where I already have my NSManagedObject, I am looking to pass it to the first SurveyViewController so it can get passed on:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
println("Sender is \(sender)")
if segue.identifier == SurveyIdentifier {
// let nav : UINavigationController = segue.destinationViewController as! UINavigationController
// let itemVC: BACUploaderViewController = nav.topViewController as! BACUploaderViewController
let surveyViewController: SurveyViewController = segue.destinationViewController as! SurveyViewController
println("survey view controller: \(surveyViewController)")
// if let destination = segue.destinationViewController as? MasterViewController {
//
// destination.workItem = sender as? Work
// }
}
}
I am fairly sure that I have to access my MasterViewController
from here by drilling down through the View Hierarchy, but not sure on how to achieve this effectively?
On a side note, the segue does work, I am presented with the correct views, but it pushes the view onto the screen twice and I'm not sure why, I can upload a gif of this if seeing what I am talking about in action might make more sense?
You can have an optional named
managedObject
in yourSurveyViewController
and then inject yourmanagedObjectContext
object fromMasterViewController
toSurveyViewController
. This code snippet is written keeping in mind that you are inMasterViewController
You can "reach down" through the hierarchy of view controllers, to get a reference to the table view controller titled "Sections" in the storyboard.
From
prepareForSegue
in yourSurveyViewController
:This passes the object to the Sections view controller. You can pass the object to the final VCs (the bad boys!) in the
prepareForSegue
of the Sections view controller. You can't do it earlier, because they are not instantiated before then.As to why the view might be pushed onto screen twice, my only guess is that you might be using
performSegueWithIdentifier
from withindidSelectRowAtIndexPath
of a table view, when the segue is also linked directly to the prototype cell.