Mac containment segues, and prepareForSegue
Mac containment segues, and prepareForSegue
- Subject: Mac containment segues, and prepareForSegue
- From: Fritz Anderson <email@hidden>
- Date: Mon, 27 Oct 2014 18:30:20 -0500
This is Yosemite, in Swift under Xcode 6.1.
The summary: I don’t understand NSStoryboard containment relationships. I’ve never received a prepareForSegue(_, sender:), and without it, I can’t figure out how to propagate data from a document into its views.
This is completely elementary. I can’t figure it out. What am I missing?
The idea I get from the WWDC presentation (2014, #212) is that when containment relationships are realized (views are put into their containers), the container controller receives a prepareForSegue(_, sender:) message. Just provide prepareForSegue(_,sender:), always do it, it’s all you need to do. Like all Cocoa innovations, it is as simple as it is delightful.
This seems important to me. If you have an NSPersistentDocument, which loads an NSWindowController, with a root NSViewController, and the view controller's business is to display objects from the documents managed-object context, the chain of prepare… calls can propagate the context pointer down to where it is needed. This is what happens with containment segues in UIKit.
The need isn’t confined to Core Data: It often happens that the contents of a document are displayed in the document's windows.
I've put prepareForSegue methods everywhere I could think of; Xcode makes sure I tag them as overrides. (I even put one in the document class, even though it’s not an override, and the document can get to the window controller at load time.)
They look like this:
override func prepareForSegue(segue: NSStoryboardSegue, sender: AnyObject?) {
let segid = segue.identifier ?? "(none)"
println("\(__FUNCTION__) hit, segue ID = \(segid)")
}
My prepareForSegue()s are never called. I had my suspicions: Interface Builder does not let you edit the containment “segues,” meaning you can’t assign an intelligible identifier to guide the prepare function in initializing the incoming controller.
As far as I can tell:
* They are “segues” only in the sense that they are lines drawn between scenes in a storyboard. They do not share any other characteristic.
* There is no property or function in NSWindowController giving access to the “window content controller,” despite IB’s insistence that there be one.
* IB affords no way to access the containment relationship or the controllers at either end of it.
I’ve watched the WWDC2014 presentation (212), and it turns out as it does so often, that it handwaves precisely what I need to know. Just provide prepareForSegue(_,sender:). Well, apparently not.
I apologize for being so annoyed, but… I’m missing something that must be there, and have been able to find no trace of it.
How do I accomplish what I need to do?
— F
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden