1

I'm working on a CoreData / Document based app. In one area of the UI I've setup a view-mode table with various columns. One column has an NSPopupButton in it with the Selected Index binding setup as Table Cell View.objectValue.startupState.

Picking any of the menu items in the popup will correctly update the startupState attribute on the entity with the index of the menu item clicked and the NSPopupButton text updates as well. I've verified the attribute value is in fact updated by saving, closing, and re-opening the document.

In another column I have an NSPopupButton bound similarly to another attribute in the same entity - Table Cell View.objectValue.mode. Depending on the mode selection it will modify the startupState value through a manual implementation of setMode which does this statement in certain cases:

[self setValue:[[NSNumber alloc] initWithInt:1] forKey:@"startupState"];

The issue I'm having is that the NSPopupButton isn't updating to show the menu item text for the selected index. As before, I saved, closed, and re-opened the document after the above code ran and the correct item was selected / text appeared so I know the setValue call updated the attribute.

Any ideas?

  • can you post more of your custom setter? Maybe will/didChangeValue messages are missing? also if is a bool, why not use `[[NSNumber numberWithBool:YES]`? – Volker Feb 07 '14 at 06:53
  • 1
    Is `startupState` in CoreData or is it derived? Is it declared @dynamic? Also, when do you set this state? Is it set while the popup is actually still popped up? – Wil Shipley Feb 07 '14 at 07:17
  • Thanks Volker! - that was the problem. –  Feb 07 '14 at 12:09
  • Wil just to answer you as well - I had created the entities in the xcode editor that manipulates Document.xdatamodeld and told it to create NSManagedObject subclasses. They are declared @dynamic. I set the initial state from code right now in windowControllerDidLoadNib. The popups are not popped up at the time. –  Feb 07 '14 at 12:12

1 Answers1

0

As mentioned in the comments, Volker's suggestion addresses the issue. willChangeValueForKey and didChangeValueForKey messages are needed around the setValue:forKey call like this:

    [self willChangeValueForKey:@"startupState"];
    [self setValue:[[NSNumber alloc] initWithInt:1] forKey:@"startupState"];
    [self didChangeValueForKey:@"startupState"];