NSToolbar in Preferences Panel
NSToolbar in Preferences Panel
- Subject: NSToolbar in Preferences Panel
- From: Saratchandra Kongara <email@hidden>
- Date: Wed, 18 Dec 2002 11:14:55 -0500
I am trying to create a toolbar for a preferences panel that is loaded
from a separate nib file (not mainmenu.nib). I have a preference
controller class that inherits from NSWindowController. The preferences
panel loads and shows up right but the toolbar is not created. I looked
at this for an hour but can't seem to find my mistake. Any help is
appreciated. Thanks.
Here is the code
In main controller
// in MainController.h
PreferenceController *preferenceController;
// In Maincontroller.m
- (void) init {
[some code here]
preferenceController = nil;
[some code here]
}
- (IBAction)showPreferencePanel:(id)sender {
// Is preferenceController nil?
if(!preferenceController) {
preferenceController = [[PreferenceController alloc] init];
}
[preferenceController showWindow:self];
}
// In PreferenceController.h
#import <AppKit/AppKit.h>
@interface PreferenceController : NSWindowController {
IBOutlet NSPanel *mainPanel; // In IB this is connected to the
preference panel
}
- (void)setupToolbar;
@end
// In PreferenceController.m
#import "PreferenceController.h"
@implementation PreferenceController
- (id)init {
self = [super initWithWindowNibName:@"Preferences"];
return self;
}
- (void)windowDidLoad {
[self setupToolbar];
}
- (void)setupToolbar
{
NSToolbar *toolbar = [[NSToolbar alloc]
initWithIdentifier:@"PreferencesToolbar"];
[toolbar setDelegate:self];
[toolbar setAllowsUserCustomization:NO];
[toolbar setAutosavesConfiguration:YES];
[toolbar setDisplayMode:NSToolbarDisplayModeLabelOnly];
[mainPanel setToolbar:[toolbar autorelease]];
}
// Delegate methods for Toolbar
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar
itemForItemIdentifier:(NSString *)itemIdentifier
willBeInsertedIntoToolbar:(BOOL)flag {
NSToolbarItem *item = [[NSToolbarItem alloc]
initWithItemIdentifier:itemIdentifier];
return [item autorelease];
}
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar {
return [NSArray arrayWithObjects:@"General", @"Sounds", @"Preview",
@"Publish", nil];
}
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar {
return [NSArray arrayWithObjects:@"General", @"Sounds", @"Preview",
@"Publish", nil];
}
@end
The file owner in the preferences nib file is set to
PreferenceController. The windowDidLoad method is also getting called,
but I don't see a toolbar. Actually there is a little bar but no labels
on it or anything.
Regards
Sarat
_______________________________________________
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.