开发者

How do you set an instance variable in one object from another?

开发者 https://www.devze.com 2023-03-25 09:55 出处:网络
I have an AppController object that contains an instance variable int adventures. This is bound to a label through Interface Builder.

I have an AppController object that contains an instance variable int adventures. This is bound to a label through Interface Builder.

I also have a subclass of NSWindowCont开发者_如何学Goroller called PopUpWindow. When the enter button is clicked the value in the text field on the pop up window should change the variable adventures in the AppController object.

Even after using @public and @package for adventures it doesn't change. I'm also trying to use

[self willChangeValueForKey:@"adventures"];

from the PopUpWindow class. Will that work across classes? How can I do this?


This may be a good place for NSNotifications you AppController could register for a named notification, my be not even care what object sends it, you PopUpWindow can then post a notification that something changed which you AppController can receive the notification. Another possibility is if the PopUpWindow is owned by the AppController controller it can have the AppController as a delegate and send a message to its delegate. You line of code

[self willChangeValueForKey:@"adventures"];

seems to suggest that is happening in you AppController, but thus is no use because this will only tell observers of you AppController.adventures that it has changed and you want it to work the other way, I am asumming the enter button is clicked it sends a message to you PopUpWindow NSWindowController.

0

精彩评论

暂无评论...
验证码 换一张
取 消