• 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
Replace NSPopupButton Menu/Binding
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Replace NSPopupButton Menu/Binding


  • Subject: Replace NSPopupButton Menu/Binding
  • From: Keith Duncan <email@hidden>
  • Date: Sun, 2 Mar 2008 23:43:48 +0000

I have an NSPopupButton whose menu I need to change based on a model property. I'm observing selection.property of the relevant NSArrayController to be notified when the menu needs to change. I need to alternate between a provided menu and a content array provided by another array controller.

I have it working with the code below it just seems awfully long winded to accomplish something seemingly simple, I was hoping someone could take a look at it and point out where I could improve my implementation.

Thanks,
Keith

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ([[keyPath lastKeyPathComponent] isEqualToString:KDAlarmTypeKey]) {
NSString *alarmNameSubpath = nil;
if ([[object valueForKeyPath:keyPath] integerValue] == ITUNES) {
alarmNameSubpath = KDAlarmNameKey;

[advancedAlarmNameButton unbind:NSContentBinding];
[advancedAlarmNameButton unbind:NSContentValuesBinding];

[advancedAlarmNameButton removeAllItems];
[advancedAlarmNameButton setMenu:[[sourceMenu copy] autorelease]];
} else {
alarmNameSubpath = KDBackupAlarmNameKey;

[advancedAlarmNameButton removeAllItems];
[advancedAlarmNameButton bind:NSContentBinding toObject:backupAlarmsController withKeyPath:@"arrangedObjects" options:nil];
[advancedAlarmNameButton bind:NSContentValuesBinding toObject:backupAlarmsController withKeyPath:@"arrangedObjects.key" options:nil];
}

[advancedAlarmNameButton bind:NSSelectedValueBinding toObject:calendarController withKeyPath:[NSString keyPathForComponents:@"selection", alarmNameSubpath, nil] options:nil];

// This is a dirty hack, setting the menu/binding the selected value seems to disable the selected menu item!?
[[advancedAlarmNameButton selectedItem] setEnabled:YES];
} else [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
_______________________________________________


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


  • Prev by Date: Handling mouse click event on a NSButton
  • Next by Date: Re: Core Data opens files as empty
  • Previous by thread: Re: Handling mouse click event on a NSButton
  • Next by thread: When in the launch cycle does coredata data become available.
  • Index(es):
    • Date
    • Thread