Programmatically replace bound objects
Programmatically replace bound objects
- Subject: Programmatically replace bound objects
- From: Claudio Procida <email@hidden>
- Date: Fri, 18 Aug 2006 01:00:00 +0200
Hi,
I have a NSPopupButton whose content is bound to a NSArray member of
a controller object. The binding has been set through IB.
Now I'm trying to replace the array programmatically, but something
goes wrong, as I get an EXC_BAD_ACCESS error.
I do understand that it's an issue related to Key-Value observing,
but I haven't a clue on how to solve this.
I've come up with this so far:
- (IBAction) updateDay:(id)sender
{
// dayMenu is the NSPopup
// Save the action
SEL action = [dayMenu action];
// Save the title to use it later
NSString *title = [dayMenu titleOfSelectedItem];
// Remove the action
[dayMenu setAction:NULL];
// Remove the target
[dayMenu setTarget:nil];
// Replace the array
[self setDays:[NSArray arrayWithObjects:@"1", @"2", nil]];
// Remove the binding
[dayMenu unbind:@"content"];
// Set the binding again
[dayMenu bind:@"content"
toObject:self
withKeyPath:@"days"
options:nil];
// Select previously selected item
[dayMenu selectItemWithTitle:title];
// Reconnect action...
[dayMenu setAction:action];
// and target
[dayMenu setTarget:self];
}
What should be the correct way to do this?
Thanks in advance.
Claudio
--
http://www.emeraldion.it
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden