Skip navigation.
 
mlRe: NSToolbar in Preferences Panel
FROM : Jan Van Boghout
DATE : Wed Dec 18 18:05:38 2002

You're not setting a label or icon or anything for your items in the 
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar
itemForItemIdentifier:(NSString *)itemIdentifier
willBeInsertedIntoToolbar:(BOOL)flag  method. You should set a label,
icon, target, selector etc.

> 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_removed>
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.

_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

Related mailsAuthorDate
mlNSToolbar in Preferences Panel Saratchandra Konga… Dec 18, 17:14
mlRe: NSToolbar in Preferences Panel Jan Van Boghout Dec 18, 18:05
mlRe: NSToolbar in Preferences Panel Saratchandra Konga… Dec 18, 18:22