Re: Get selected NSManagedObject from a NSPopUpButton
Re: Get selected NSManagedObject from a NSPopUpButton
- Subject: Re: Get selected NSManagedObject from a NSPopUpButton
- From: Niko Matsakis <email@hidden>
- Date: Sat, 8 Oct 2005 18:39:02 +0200
More specifically, what I do is this:
0. Bind the values binding from button to controller
1. Bind the "selectedIndex" from the button to the controller's
selectedIndex
2. To get the current selected item, do either:
[controller selection]
or
[[controller arrangedObjects] objectAtIndex:[controller
selectionIndex]];
For part 2, the two choices are basically equivalent, but the former
returns a proxy and the latter returns the actual NSManagedObject, so
I prefer the latter. In fact, I have created a handy category for it:
@implementation NSArrayController (XXX)
- (id) selectedObject
{
unsigned int selidx = [self selectionIndex];
if (selidx != NSNotFound)
return [[self arrangedObjects] objectAtIndex:selidx];
return nil;
}
@end
There may be a better way to do this, but this is the best one I have
found. It also does not involve having any IBOutlets pointing to the
actual NSPopUpButton, which seems clean to my sensibilities.
Niko
On Oct 8, 2005, at 4:25 PM, Marcus S. Zarra wrote:
Make sure you have a reference to the NSArrayController then you can
call selectedObjects on the array controller which will give you the
selected objects as an array.
On 10/8/05, Gian Marc Cadosch <email@hidden> wrote:
I've found lots of good information for programming core data
applications. But now I have a problem for which I haven't found a
solution yet:
I'd like to get the managed object which is selected in a popupmenu.
The popup menu is bound to an NSArrayController which receives the
data from core data.
Thanks for helping.
Marc
_______________________________________________
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
_______________________________________________
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
_______________________________________________
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