开发者

Display Window with Cocoa Framework in Xcode

开发者 https://www.devze.com 2022-12-14 15:32 出处:网络
I\'m building a framewor开发者_JS百科k in Xcode, and I need to display a window when a function is called. How do I get my framework to display a window that I build in Interface Builder? Step by step

I'm building a framewor开发者_JS百科k in Xcode, and I need to display a window when a function is called. How do I get my framework to display a window that I build in Interface Builder? Step by step instructions would be greatly appreciated!

Thanks, Chetan


You'd call it like this:

    MyWindowController* controller = [[MyWindowController alloc] 
     initWithWindowNibName:@"Foo"];
    [controller showWindow:nil];

Where Foo is the name of the nib file, and MyWindowController is a subclass of NSWindowController that you set to be the owner of the nib file.

In this case, it's important to subclass NSWindowController because it will automatically search for the nib file within the bundle that the class lives in.


Use an NSWindowController as the window's File's Owner, and then just call [myWindowController showWindow:nil].


That is probably caused by not keeping a strong reference to the created NSWindowController. If you don't keep it, the object will be deleted.

0

精彩评论

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