Re: Best way to replace one view with another within a superview
Re: Best way to replace one view with another within a superview
- Subject: Re: Best way to replace one view with another within a superview
- From: Matt Mashyna <email@hidden>
- Date: Sun, 17 Feb 2008 18:16:58 -0500
On Feb 17, 2008, at 6:04 PM, Timothy Mowlem wrote:
Hello,
I am writing an application which has a GUI layout similar to the 3-
pane view used by iTunes, with a sidebar of categories on the left,
an object view in the top right hand corner and a details view for
the chosen objects in the bottom right hand corner. However the
contents of the top and bottom right hand views need to vary
depending on the current application state, e.g. the current
selection in the left hand pane.
In Java one would create a JPanel which contained the UI to be shown
in each state and then remove the old panel from its containing
panel and replace it with the new one programmatically when it needs
to be changed. Also in most cases the UI is constructed in code
rather than using a tool like IB.
However in Cocoa I can't see how to do this. There seem to be
several issues:
(1) controls are added directly to the window's content view rather
than to a panel like in Java
(2) IB doesn't seem to have any way to design several sets of
components as a group and be able to switch between them
Note that I don't want to use a tabbed pane here as the context may
completely change so tabs wouldn't really be appropriate. One
solution I can envision is a table with each view in a separate row
of a single column table and then scrolling the selection to show
the required view. But this seems like a hack and I haven't explored
it.
I would like to ask for advice on the best way to do this in Cocoa/
Interface Builder? Its a fairly common design so presumably there
are one or more recommended approaches?
Thank you,
Timothy Mowlem
_______________________________________________
I've done what I think you are asking about many times and the way I
do it is to make an NSTabView with the variations I want each laid out
in its own tab. I connect all the outlets and set the tab view to be
"tabless" in IB. When I want to change the look, I just switch tabs
programatically. If you make your view controllers listen for
notifications you can keep all the hidden tabs views' contents
synchronized. Whenever a user changes one you have it post a
notification so the others pick it up. You can connect your outlets to
a view that has the superset of view items.
Hope that was what you were asking about.
Matt
_______________________________________________
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