• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Utility window architecture question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Utility window architecture question


  • Subject: Re: Utility window architecture question
  • From: Brock Brandenberg <email@hidden>
  • Date: Fri, 17 May 2002 13:20:10 -0500

Hi Glen.

My question is, does anyone have a suggestion for a good code
architecture for a panel that has its content view swapped out at
runtime? For example, should I be creating a view controller for each
custom view that is responsible solely for that view's contents, then
load and unload each controller and associated nib as appropriate?

That's actually how Apple suggests doing things, and I don't think you're likely to find a better approach. In a document somewhere in the Cocoa documentation (even knowing it's there, I can't always find it), Apple talks about using NSWindowControllers as *view* controllers. The heart of the trick is quite simple: grab the content view, retain it, then set the window to nil.

(If you don't retain the content view, it'll get discarded at the same time as the window.) The controller won't try to reload the window, and all the connections established by the nib file remain intact. If the views have to communicate with each other (unlikely, from the sound of it), you can either tell each view controller what panel contains it, or you can have the controllers send notifications which the panel receives and acts on.

Thanks for the reference. I didn't see the info about using NSWindowControllers as *view* controllers either, but it makes perfect sense once you see it. I figured the MVC structure fit the needs of a multi-view inspector fairly well. I just didn't want to hack up my code until I had some affirmation that I hadn't missed something obvious.

Whether to load and unload, or just load and keep around, would depend on how often the displayed view changes, I'd think. If the view changes rarely, then loading and unloading probably makes sense, since there's little point in keeping the view and its controller around when it's not being used. However, if the view could change often, or on short notice, you might be better off keeping all the possible views and their controllers handy for fast switching.

Good point. I will probably keep them around, because the grouping of controls affords frequent switching and I don't want to thrash the nib files too much.

(In fact, if the view *does* change frequently, you might want to wrap all the views up in a tab view with no actual tabs. [IB lets you create such things.])

That's a really good suggestion. It's a much cleaner concept to switch tabs than to swap content views.

Thanks,
Brock Brandenberg

----- industrial design @ bergdesign.com ------
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Utility window architecture question (From: email@hidden)

  • Prev by Date: Cocoa Logo
  • Next by Date: Re: Utility window architecture question
  • Previous by thread: Re: Utility window architecture question
  • Next by thread: Re: Utility window architecture question
  • Index(es):
    • Date
    • Thread