Hi, I have 2 NSTextFields for data entry, an NSButton and NSPopUpButton.
When the button is pressed the 2 NSTextFields are entered into an NSMutableDictionary as the 'object' and 'key'. Also the NSTextField for the 'key' is also added to the NSPopUpButton.
The goal is the user can enter their own items, the 'KEY' like a Sword and then '25' in the second NSTextField. Later the user can use the NSPopUpButton to select the item 'Sword' and in an NSTextField, called bonus, the number '25' is displayed as a string.
All my code works for the NSPopUpButton, but I don't think I am populating the NSMutableDictionary correctly. I know the Dictionary needs to have a 'nil' that defines the end of it but the mutableDictionary starts with no entries until the user adds them. I think that is my problem area.
@interface
@implementation
I have been scratching my head for a while.
Thanks,
-Lars
When the button is pressed the 2 NSTextFields are entered into an NSMutableDictionary as the 'object' and 'key'. Also the NSTextField for the 'key' is also added to the NSPopUpButton.
The goal is the user can enter their own items, the 'KEY' like a Sword and then '25' in the second NSTextField. Later the user can use the NSPopUpButton to select the item 'Sword' and in an NSTextField, called bonus, the number '25' is displayed as a string.
All my code works for the NSPopUpButton, but I don't think I am populating the NSMutableDictionary correctly. I know the Dictionary needs to have a 'nil' that defines the end of it but the mutableDictionary starts with no entries until the user adds them. I think that is my problem area.
@interface
Code:
NSMutableDictionary *skills;
@implementation
Code:
- (IBAction)addSkillPrefButton:(id)sender {
[popUpButtonDisplay addItemWithTitle: [skillNamePref stringValue]]; // adds item to popUp
[skills setObject:[skillBonusPrefField stringValue] forKey:[skillNamePref stringValue]]; // adds obj and key to Dict.
[skillNamePref setStringValue:@"-"]; //resets textfield
[skillBonusPrefField setStringValue:@"-"]; //resets textfield
}
I have been scratching my head for a while.
Thanks,
-Lars