Re: View swapping questions
Re: View swapping questions
- Subject: Re: View swapping questions
- From: Andrew Merenbach <email@hidden>
- Date: Tue, 4 Nov 2008 10:38:45 -0800
On Nov 4, 2008, at 10:00 AM, Robert Mullen wrote:
I am attempting to swap views somewhat like XCode does between
project and debug modes. This is being done to an existing project
that has the main windows content view set in IB. I have tried to
store the initial view before replacing it with the new view using
code similar to this:
oldView = [window contentView];
[window setContentView:newView];
and then swapping them back out on a segmented cell action
[window setContentView:oldView];
This is pseudo code with the actual views being linked up via IB so
it may not be perfect but I am trying to understand conceptually if
this should work. I do need to preserve the state of the controls in
both views so that toggling back and forth brings you to the same
exact view as before.
Am I barking up the wrong tree?
TIA
Greetings, Robert,
You aren't in my opinion barking up the wrong tree, per se, but
there's a simpler way, IMHO, that I use with a couple of programs that
doesn't involve actually swapping the window's content view, but
rather constructs tabs for a tabless tab view. Then you can wire up
the segmented control directly to the tab view in Interface Builder --
simply control-drag from the segmented control to the tab view, and
select -takeSelectedTabViewItemFromSender: there. Note that unless
you have the same number of tabs as you have segmented cells, you're
liable to crash, but that doesn't sound like it'd be a problem.
So, to make it brief:
1. Create a tablesss tab view in Interface Builder and a segmented
control to go along with it.
2. Configure your segmented cells as you wish, then wire the control
up to the tab view.
3. In code, repetitively do something like the following (typed in
Mail):
NSTabViewItem *item1 = [[NSTabViewItem alloc]
initWithIdentifier:@"myIdentifier1"];
[item1 setLabel:@"My Label 1"];
[item1 setView:myView1];
Do this for all of your views. The best way to do this, I've found,
is to use NSViewControllers (if you can target Leopard), with each
view in a separate nib/xib. Then you can configure your view
controllers and just refer to [myViewController1 view] -- it'll do the
heavy lifting for you. Note that, regardless of whether you use any
view controllers, you won't need to worry about swapping anything at
all -- the system will handle it for you.
Hope this helps!
Cheers,
Andrew
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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