Question

I have an Object bound to the user interface with a NSObjectController. I am able to archive the Object and unarchive it later. This works fine so far. In the Debugger I can see the object holds the data I saved in a previous session. The remaining problem is: The user interface does not refresh. I guess I have to tell the NSObjectController somehow he has to deal with an other object. But I don't know how. I tried newObject but that did not work at all.

At the moment my code looks like this:

if ([aOpenPanel runModal] == NSOKButton)
{
    NSString *filename = [aOpenPanel filename];
    rpgCharacter = [NSKeyedUnarchiver unarchiveObjectWithFile:filename];

    // [myCharacterController DoSomething] ???
}

rpgCharacter should be the object for the myCharacterController.

Was it helpful?

Solution

What you are doing is setting the rpgCharacter iVar directly. In order to trigger KVO you need to do this in a different way either:

if you are using Objective-C 2.0 and property syntax:

if ([aOpenPanel runModal] == NSOKButton)
{
    NSString *filename = [aOpenPanel filename];
    self.rpgCharacter = [NSKeyedUnarchiver unarchiveObjectWithFile:filename];

}

or, if you are using KVC directly and have a correctly named setter:

if ([aOpenPanel runModal] == NSOKButton)
{
    NSString *filename = [aOpenPanel filename];
    [self setRpgCharacter:[NSKeyedUnarchiver unarchiveObjectWithFile:filename]];

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top