• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSToolbarItem not displaying
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSToolbarItem not displaying


  • Subject: NSToolbarItem not displaying
  • From: Kevin Walzer <email@hidden>
  • Date: Thu, 17 Feb 2011 10:51:52 -0500
  • Organization: WordTech Communications LLC

Hi,

I'm trying to create an NSToolbar programatically, and am having some problems with all of my NSToolbarItems displaying (all basic items, no custom views). Specifically, rather than both items in my test case displaying correctly, the second item is displaying twice.

What I'm doing is setting up the attributes for each NSToolbarItem (identifier, label, selector, etc.) in an NSMutableDictionary, adding each dictionary to an NSMutableArray (toolbarItems), adding those items to another NSMutableArray to set the toolbar's default items (defaultItems) and allowed items, and then iterating through the defaultItems array to insert the toolbar item. (Use of NSLog statements shows that all intended items are being correctly added to the various arrays.)

Here's my code to set up the default items in the toolbar:

- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar {

  NSMutableArray  *defaultItems = [[NSMutableArray alloc] init];
  for (NSDictionary *element in toolbarItems) {
    [defaultItems addObject: [element objectForKey:@"itemIdentifier"]];
  }

  return defaultItems;

}

- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar
     itemForItemIdentifier:(NSString *)itemIdentifier
 willBeInsertedIntoToolbar:(BOOL)flag {

  NSToolbarItem  *toolbarItem;

  for (NSDictionary *element in toolbarItems) {

toolbarItem = [[NSToolbarItem alloc] initWithItemIdentifier:[element objectForKey:@"itemIdentifier"]];
[toolbarItem setLabel:[element objectForKey:@"buttonLabel"]];
[toolbarItem setToolTip:[element objectForKey:@"toolTip"]];
[toolbarItem setImage:[[NSImage alloc] initWithContentsOfFile:[element objectForKey:@"imagePath"]]];
[toolbarItem setAction:@selector(runScript:)];
[toolbarItem setTarget:self];
NSLog(@"I am adding %@", [element objectForKey:@"itemIdentifier"]);
[toolbarItem setEnabled:YES];
NSLog(@"the label is %@", [toolbarItem label]);
}


  NSLog(@"the final label is %@",[toolbarItem label]);
  return toolbarItem;

}

When the code iterates through the NSToolbarItems, the correct itemIdentifier is logged, i.e. "I am adding item1," "I am adding item2," and so on. However, after the loop, the "final label" is always logged as the label for "item2." item1 simply disappears; item2 is displayed where item1 should be, and item2 is correctly displayed in its own intended spot. This is where item1 is disappearing, since the log statement show that it is correctly retrieved from the array.

Any suggestions as to what I'm doing wrong here?

--Kevin

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
_______________________________________________

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


  • Follow-Ups:
    • RE: NSToolbarItem not displaying
      • From: Lee Ann Rucker <email@hidden>
    • Re: NSToolbarItem not displaying
      • From: Graham Cox <email@hidden>
  • Prev by Date: Multithread, Window, Event, Runloop, ... => Headache
  • Next by Date: Re: Programmatically created NSView subclasses, and mouse events
  • Previous by thread: Re: Multithread, Window, Event, Runloop, ... => Headache
  • Next by thread: Re: NSToolbarItem not displaying
  • Index(es):
    • Date
    • Thread