开发者

Cocoa controller question

I have a two windows app. First one is the default window. Second one is created using a custom controller:

CCCVentanaBloqueo *ctrl = [[CCCVentanaBloqueo alloc] initWithWindowNibName:@"VentanaBloqueo"];
CCWVentanaBloqueo *ventana = (CCWVentanaBloqueo*)[ctrl window];

ventana contains one label connected to one CCCVentanaBloqueo controller outlet via XCode IB. If I try two modify that outlet from main window via CCCVentanaBloqueo controller outlet, no change succed.

I can see that outlet has a nil value. I can see also that two CCCVentanaBloqueo objects 开发者_运维百科are created (two calls to awakeFromNib function) when [ctrl window] line gets executed.

I suppose *ctrl references wrong controller but I don't know why two controllers are created.

Do you know why? Any other way to make changes to not main window from main window controller?


Declare the second window controller as an instance variable of your app controller and make it a property. Then you can easily send messages to it's IBOutlets (provided they are also properties) via the appDelegate.

Let's say you're going to have window A send window B a message. In Window A's controller you might have a method like this:

- (IBAction)messageWindowB:(id)sender {

       myAppDelegate *appDelegate = [NSApplication sharedApplication] delegate];
       [appDelegate.windowB.theView doSomething];

}

Honestly, I am not sure if I entirely understood your question. Also, this is a quick and dirty approach. So if anyone else has suggestions, please be my guest!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜