How to load xib and display window of custom framework from a application

1.3k views Asked by At

I created a framework and added a xib file named "MyXibFile". I created a separate application and added this framework to it. I want to load this .xib file to display the window from it.

I am using the following code snippet which is not working

-(void)launchDownloaderWindow
{
    if (![NSBundle loadNibNamed:@"Download" owner:self]) 
    {
        NSLog(@"Nib loading failed");;
    } 

    [appWindow makeKeyAndOrderFront:nil];
}

I can see the message in the console "Nib loading failed" Any suggestion how to solve this?

1

There are 1 answers

0
Keith Smiley On

I can think of a slightly different way of doing this. In your created framework create a class, possibly an NSWindowController, and have it load and return the window for you. For example after importing the framework you could initialize your window controller and create a strong reference to the window it creates.

WindowController.m

@implementation WindowController

- (id)init {
    self = [super initWithWindowNibName:@"WindowController"];
    ...
    return self;
}

@end

MyApp.m

- (void)showSomeWindow {
    WindowController *wc = [[WindowController alloc] init];
    self.appWindow = wc.window;

    [self.appWindow makeKeyAndOrderFront:self];
}