Objective Coder
Objective Coder

Reputation: 557

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 problem, 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?

Upvotes: 0

Views: 5131

Answers (2)

GarethPrice
GarethPrice

Reputation: 1104

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.

Upvotes: 4

Rudy Velthuis
Rudy Velthuis

Reputation: 28806

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.

Upvotes: 0

Related Questions