I am having an NSPopUpButton with pullDown and added few menu items(image and title) to the menu and added that menu to the Button cell.
Initially I am assigning the First menu item of the menu to Button cell to display in NSPopUpButton.
When I tapped the NSPopUpButton a menu is displayed with all the items I added earlier and when I select an item from the menu its data is not updated to NSPopUpButton. i.e is title is getting updated and the image is not..
Can anyone suggest me how can I resolve this
The code I written :
In ButtonCell class:
NSMenu* newMenu = [[NSMenu alloc] initWithTitle:@""];
[newMenu setAutoenablesItems:YES];
[[self optionMenuController] insertItemsInMenu:newMenu atIndex:0];
if(isFromSetOption)
{
[self setMenuItem:[newMenu itemAtIndex:1]];
isFromSetOption = NO;
}
//[newMenu insertItemWithTitle:@"dummy" action:nil keyEquivalent:@"" atIndex:0];
[self setMenu:newMenu];
[newMenu release];
In OptionMenuController :
- (void) insertItemsInMenu:(NSMenu*)menu atIndex:(NSInteger)insertIndex
{
for( NSMenuItem* item in [self createMenuItems] )
{
[menu insertItem:item atIndex:insertIndex++];
}
}
- (NSMenuItem*) menuItemForOption:(AMOptionMenuItem*)option inGroup:(AMOptionMenuItem*)group
{
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:[option title] action:@selector(optionChosen:) keyEquivalent:@""];
[menuItem setIndentationLevel:1];
[menuItem setTarget:self];
[menuItem setEnabled:YES];
[menuItem setImage:[NSImage imageNamed:[option imageTitle]]];
/* if([[option identifier] isEqualToString:@"Color"])
{
[menuItem setImage:[NSImage imageNamed:@"cabinet"]];
}
else{
[menuItem setImage:[NSImage imageNamed:@"YieldIcon.png"]];
}
*/
NSString* keypath = [NSString stringWithFormat:@"%@.is%@", [group identifier], [option identifier]];
[menuItem setRepresentedObject:keypath];
NSDictionary *bindingOptions = nil;
[menuItem bind:@"value" toObject:self withKeyPath:keypath options:bindingOptions];
return [menuItem autorelease];
}