Re: Tabbed preference panels
Re: Tabbed preference panels
- Subject: Re: Tabbed preference panels
- From: Negm-Awad Amin <email@hidden>
- Date: Fri, 22 Aug 2008 18:56:12 +0200
Am Fr,22.08.2008 um 18:29 schrieb Sumner Trammell:
Hi, I'm working on a preferences panel. I want to build a compound
panel like the kind seen in most mainstream apps today: a toolbar on
top with "tabbed" view switching. The panel changes its appearance
depending on which 32x32 toolbar icon you have selected.
I'm not sure where to start. Looking for examples, I've looked in
Safari's app bundle resources dir, and I see that Safari uses separate
nibs per preferences tab. When I open one of these nibs, I see a
window object, and that window object has the preference tab's layout.
Pretty straightforward. Of course, Safari is not open source, so I
can't go any further and see how this design works.
Looking at the source for Transmission, I see they've taken a
different approach, which is to have one PrefsWindow.xib, and in that
xib, a number of View objects, one for each tab. Open the view object
representing a particular preference tab, and you see its layout. I
have not studied the Transmission source yet to see how they make it
all work.
So we have at least 2 accepted ways of doing the tabbed preference
panel thing. But I'd like a better understanding of the hows and why's
overall. Can anyone point me to some Cocoa programming guide docs, or
programming topics docs, on tabbed preference panels? (Are they even
called "tabbed preference panels?")
There are some different problems:
1) The selection bar
You can use a toolbar from IB and put some items there. If you want
the items to be selected (pressed into the toolbar) you need a
delegate, which tells the toolbar, which items are selectable. In most
cases all items are selectable in such a pref-window. So you can do a
hack by writing a method in the toolbar delegate:
- (NSArray*)toolbarSelectableItemIdentifiers:(NSToolbar*)toolbar;
{
NSMutableArray* selectables = [NSMutableArray array];
for( NSToolbarItem* item in [toolbar items] ) {
[selectables addObject:[item itemIdentifier]];
}
return selectables;
}
(Otherwise you get a problem with item identifiers.)
2. Of course you have to connect the items to an action. The action
should change the content of the window. There are two approaches:
2.1. TabView
Use a tabview with the different selections and simply switch the tab
view.
2.2. View hierarchy
Get a seperate view for each selection (inside the same nib or one nib
per view) and exchange the actual view with this view (-
removeFromSuperview:, -addSubview:). You have to take care about:
- At the beginning you need one view as a placeholder. (You do not
need it, but it is easier to me to handle it.) In -awakeFromNib you
can replace that view with the view, which needs to be displayed
first. So the placeholder view is a simple placeholder, say NSBox. To
me this is easier to handle in IB (Autosizing and so on).
- Every time you replace the view, because the selection changed, you
have to calculate the frame of the newly inserted view from the last
displayed view.
- Memory mangement: It depends a little bit on the way you load/create/
refer to the different views. In any case remember: If you replace a
view, this view isn't retained by its superview any more and will
disappear, if you or somebody else do no -retain on it. If it is in a
nib, the nib will hold the view. If you put each view in an extra nib,
the extra nib will hold it. (Unloading the nib will unload the view,
reloading the nib will reload the view.)
This is the basic approach, I use it in this cases. I think there are
different ways and there is no "Switching Window Documentation". But I
think you're having now enough keywords for your own search.
Cheers,
Amin
Thanks,
-s
_______________________________________________
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
Amin Negm-Awad
email@hidden
_______________________________________________
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