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: Dave Hersey <email@hidden>
- Date: Sun, 17 Feb 2008 18:40:20 -0500
I've always done this by creating separate views in IB for whatever I
needed (a table view, matrix view, control sets, etc.) and having
custom views to hold them in the main window. Then you just need a
method to remove the current subview (retain the subview for reuse,
then removeFromSuperview), set the new subview's size to the
superview's size (setFrame/setBounds) and finally swap in the new
subview (addSubview).
It sounds more messy than it is. You basically have superviews to hold
the changing content, then have a method to size your subviews
appropriately and swap them into these views as needed.
- d
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
_______________________________________________
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