Re: Core Data NSPopUpButtonCell and NSNumber
Re: Core Data NSPopUpButtonCell and NSNumber
- Subject: Re: Core Data NSPopUpButtonCell and NSNumber
- From: Fritz Anderson <email@hidden>
- Date: Sun, 23 May 2010 12:39:26 -0500
On 23 May 2010, at 12:11 PM, James Maxwell wrote:
> This shouldn't be a difficult problem, but how do I make a NSPopUpButtonCell load a list of numbers, and return the value of the number when selected? Originally I used a ComboBox, with pre-programmed values from IB, but it returned strings, not NSNumbers. This really should be simple, and maybe it is, but I can't find a simple way to do it. I'm using Core Data, and the object I'm trying to set in my model is type Integer 16.
Shortest answer: [aString integerValue].
Your controller (or something it owns) could have a property that's an NSArray of objects that in turn have an NSString property for the item title and an NSNumber property for the item value, and bind the two to the popup button bindings, and bind your model property to the selected value. (Considerable hand-waving; sorry.)
Or, if the menu doesn't vary, use setTag: on each item, using the desired integer. On selection, theNSNumber = [NSNumber numberWithInt: cell.selectedITem.tag].
Or, if the item titles all begin with the integers you're interested in (untested, typed in Mail)...
NSString * title = cell.selectedItem.title;
NSInteger titleAsInt = title.integerValue;
NSNumber * theNSNumber = [NSNumber numberWithInteger: titleAsInt];
— F
_______________________________________________
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