> On Mar 24, 2017, at 3:49 PM, Quincey Morris > <[email protected]> wrote: > > On Mar 24, 2017, at 11:11 , Daryle Walker <[email protected] > <mailto:[email protected]>> wrote: >> >> I have a re-explaination, including a picture, at … > > I think I’m beginning to understand what you’re asking. Part of the problem > is that Apple has never properly documented the use of storyboards on macOS, > and there seems to be no standard pattern for doing many of the things that > we used to do when using XIBs instead.
So, there is no API to getting at runtime the top-bar items that you add?! (If you don’t mind a subclass, you can drag items from the storyboard to the corresponding subclass definition file.) > If I understand correctly, you have a window with an associated custom > subclass of NSWindowController. The root view controller is a > NSSplitViewController, with a NSViewController on the left, and a > NSTabViewController on the right. Each of the tabs has a NSViewController, > with a table view in one tab and a text view in another tab (based on what > you said in earlier posts). My structure may not be exactly the same as > yours, but it’s something like that, right? It’s a top/bottom split view. And the table view is on top, while the text view is one of the tabs in the bottom half. > Now, in some of the NSViewController views, you need to use a > NSArrayController or NSObjectController, which is added directly to the > storyboard. The question then becomes: how to connect the array or object > controller to its content (which lies outside the storyboard) and/or > establish an outlet to the array or object controller that gives you a > programmatic reference to the object in the nib. (In a XIB-based design, this > is straightforwardly done via the File’s Owner pseudo-object.) > > I think the short answer is that you should create a subclass for each > NSViewController in your tree of controllers. You *could* subclass the split > and tab view controllers too, but there’s no real need. The subclass would > contain whatever outlets and properties providing access to model data it > needs for its particular view. Each VC would have its own set of object > and/or array controllers, and each object/array controller would bind or > connect to its own VC. I was trying to avoid using subclasses. > The only remaining problem is how to establish programmatic references > between the WC and the VC subclasses, in particular how to make model data > available to the VCs. > > — If this is a non-document app, I would recommend you create a class > property in your WC subclass that holds a reference to your singleton WC of > that subclass. This reference would be set in an override of the WC init > method. > > — If this is a document-based app, I would suggest that your VC subclasses > use KVO to observe themselves along key paths of the form > “view.window.windowController.document.model…”. You could, for example, > create a derived “model” property that returns > “view.window.windowController.document.model”, along with a class > “keyPathsOfValuesAffectingModel” method to make the derived property KVO > compliant. You can then bind UI elements through the model property. > > The only thing to be careful of is that the derived “model” property will be > nil initially, so your UI has to do something sensible until the model > reference is available (in particular, not crash). > > — Alternatively, you can have the WC walk the tree of VCs, injecting a > reference to itself in each VC of known custom subclasses. > I first kept my object and array controllers in my window controller class. I walked the controller tree, keeping references to the table and text views, and adding the appropriate controller as the view controller’s represented-object. (I’m not subclassing, so they have no other use.) I used the represented-object as the controller key while building Cocoa Bindings. > Does any of that help? — Daryle Walker Mac, Internet, and Video Game Junkie darylew AT mac DOT com _______________________________________________ Cocoa-dev mailing list ([email protected]) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
