开发者

How to set delegate to an class that interface builder creates?

I'm creating a program in Xcode that has two nib files. Each one is containing a separate NSWindow. The first on is the startup one from MainMenu.xib. When I click a button in that on I use this to load my second view (From the app delegate):

 myControl = [[NSWindowController alloc] initWithWindowNibName:@"ServerWindow"];
[myControl showWindow:self];

This second XIB (ServerWindow.xib) is loaded without a proble开发者_JAVA百科m, and it's got a ServerWindow.h and ServerWindow.m connected to it (Draged in an NSObject and pointed it to this class in IB.

I then go on and make some settings in ServerWindow and when I close this window I want to delegate these settings back to my original class (App delegate).

The problem is, though I'm not creating an instance of my class (ServerWindow.h), Interface Builder those this in some magical IB-way when It loads the XIB, I cant's set my original class as it's delegate.

How can I transfer a message back to my original class?


Drag an object into your second xib and then set the class to your original class in the right/inspection/attributes panel. Then ctr click - drag to the just created object from the controller object and set it as a delegate.


I'm not quite sure I understand you correctly, but can't you set yourself as delegate in awakeFromNib or even in Interface Builder? You can also access the WindowController's window property to get at the server window.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜