1

While I'm quite experienced with developing iOS applications, I'm still a bit of a newbie with regards to Mac OS X application development.

The issue I'm having is the following ...

I've created a UI with a combo box, several text fields and 2 text views. Whenever the user changes the selected value of the NSComboBox I want to safe all currently displayed values to my model. In my current implementation I make use of a delegate method of NSComboBoxDelegate to save the data into the model (-comboBoxWillPopUp:) - another delegate method is used to load the data (-comboBoxSelectionDidChange:). All works as expected for my text fields, but I'm having trouble saving the data of the text views to the model and I can't figure out what's the cause.

With regards to the NSTextView I have the following issue: instead of just saving the values for the old localization in the model and loading the values of the newly selected localization somehow there seems to be a bit of caching going on - the values of the old localization are copied over for the newly selected localization in the textview and this happens in my data model as well.

view controller:

- (void)comboBoxSelectionDidChange:(NSNotification *)notification
{    
    NSInteger index = [comboBox indexOfSelectedItem];
    NSString *selectedLocale = [supportedLocales objectAtIndex:index];

    text = [deal valueForContentItemWithType:SDDealContentItemTypeTitle locale:selectedLocale];
    titleField.stringValue = text ? text : @"";

    text = [deal valueForContentItemWithType:SDDealContentItemTypeText locale:selectedLocale];
    textView.string = text ? text : @"";
}

- (void)comboBoxWillPopUp:(NSNotification *)notification
{
    NSInteger index = [comboBox indexOfSelectedItem];
    NSString *selectedLocale = (index != NSUIntegerMax) ? [supportedLocales objectAtIndex:index] : [supportedLocales objectAtIndex:0];

// works fine ...

    text = titleField.stringValue;
    [deal setValue:text forContentItemWithType:SDDealContentItemTypeTitle locale:selectedLocale]; 

// has issues ...

    text = textView.string;
    [deal setValue:text forContentItemWithType:SDDealContentItemTypeText locale:selectedLocale]; 
}

model:

- (id)valueForContentItemWithType:(SDDealContentItemType)type locale:(NSString *)locale
{
    SDDealContentItem *item = [self contentItemWithType:type locale:locale];

    return item ? item.value : nil;
}

- (void)setValue:(id)value forContentItemWithType:(SDDealContentItemType)type locale:(NSString *)locale
{    
    SDDealContentItem *item = [self contentItemWithType:type locale:locale];
    if (!item)
    {
        SDDealContentItem *item = [SDDealContentItem contentItemWithType:type locale:locale];
        item.value = value;

        self.items = [self.items arrayByAddingObject:item];

        return;
    }

    item.value = value;
}
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
Wolfgang Schreurs
  • 11,779
  • 7
  • 51
  • 92
  • 1
    Stepping through those two problematic lines of code, do you see the expected string assigned to `text in your `text = textView.string;` line? If so, then the problem would be in your model's `setValue` method. Also, what is `selectedLocale` set to when `text = textView.string;` hits in your debugger? – Michael Dautermann Jan 13 '12 at 13:52
  • Yes, the values are assigned to the variables, but there seems to be some sort of weird issue. Instead of only changing the value for the last selected localization, often values are also changed for the newly selected localization. I'll investigate my model a bit more. – Wolfgang Schreurs Jan 13 '12 at 14:21
  • Sweet, you helped me fixed the issue by making me look at the model. I used *strong* instead of *copy* for my properties and that caused the issues. Much props to you! – Wolfgang Schreurs Jan 13 '12 at 14:25

0 Answers0