> Le 4 janv. 2017 à 20:37, Quincey Morris <quinceymor...@rivergatesoftware.com> > a écrit : > > On Jan 4, 2017, at 02:30 , Daryle Walker <dary...@mac.com> wrote: >> >> I always had to guess how to retain a non-document window. I usually get it >> after a bunch of hacking, but I want more official advice. Like I can get >> from here. >> >> I think there are three scenarios: >> - a window with 0 or 1 instances like an app-global photo album >> - arbitrary number of independent windows with the same type, like a web >> browser >> - an auxiliary window supporting a normal one, changing its displayed data >> when the top normal window changes. It should be hidden when no normal >> windows are open. >> >> Whatever retaining system is used needs to handle when a window closes. It >> either sets a single handle to NIL, removes the pointer from an array, or >> hides the window (still holding a retain). > > It’s a little bit complicated because there is history to window management. > For example, windows have a “release when closed” option (for historical > reasons) that interacts with the nib-loading machinery. > > However, I think the real answer to your question is pretty easy: always, > always use a window controller for each window. The window controller manages > the lifetime of the NSWindow object, and you manage the lifetime of the > window controller objects by keeping a reference (to the one window > controller, or an array of references to multiple window controllers) in a > known location. It’s often done as a property on the application delegate > object, but it could also be a NSWindowController-subclass static property, > depending on your architecture. > > If you’re using storyboards, you should already have one window controller > per window. There may be nothing else to do in this case. However, I don’t > know that there’s a direct way to get a programmatic reference to the window > controller easily. If you need it, you may have to resort to an indirect > technique.
When using storyboard, the only way to instantiate window is by getting a reference to the window controller (by using -instantiateControllerWithIdentifier:), so it should not be an issue. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com