Gab
Gab

Reputation: 19

How do I attach a child window/panel to parent window in Objective C

The answer eludes me I have no idea and I've searched everywhere on google.

The problem: I already have both windows built and am NOT coding them programatically... so

[window addChildWindow:window ordered:....] etc doesn't help because I don't know how to create a "name" for my pre fabricated windows in Interface Builder...and I can't find a tutorial on what to bind/link

So Im getting frustrated.

Basically Ive already made a main window and a panel..and want the panel as a child of main.

What do I do?

Upvotes: 0

Views: 2447

Answers (1)

Fruity Geek
Fruity Geek

Reputation: 7381

The easiest way is to define IBOutlets in your application delegate.

@interface FFAppDelegate : NSObject <NSApplicationDelegate>

@property (assign) IBOutlet NSWindow * window;
@property (assign) IBOutlet NSPanel * childPanel;

@end

Now connect the IBOutlets to the window objects in your xib file. Now the windows will be created for you by AppKit during application launch.

You still have to implement a line of code to add the panel as a child window of the main window.

@implementation FFAppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application
    [[self window] addChildWindow:[self childPanel]
                          ordered:NSWindowBelow];
}

@end

Upvotes: 1

Related Questions