views:

49

answers:

1

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.

+1  A: 

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]];

}
Abizern
Works fine. Thanks. So I need to set the object via a property or an accessor-method to trigger the KVO? Yes, makes perfectly sense to me now.
Holli
Yes. Except for initialiser methods where they should be set directly http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/ObjectiveC/Articles/ocAllocInit.html#//apple_ref/doc/uid/TP30001163-CH22-SW1
Abizern