开发者

Window-less Cocoa application

I'm a complete beginner in Objective-C and Cocoa.

I would like to create a window-less application, which just shows a NSStatusItem in the system tray. The tray works fine, however, there is one problem.

For some reason my application automatically creates a window for me, which I do not want.

I thought it was caused by the automatic Interface Builder template created when I created the application in Xcode, so I deleted the .nib file from the project. However the window still gets created.

The only lines that contain a reference to the window are in the header:

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

and in the implementation file:

@synthesize window;

Both were added automatically, I did not write this.

How do I just stop the app from creating a window? I even tried to removing all references to window from the code, including the NSWindow *window, but the window still got created.

My temporary fix right now is to call [window close]; in the开发者_如何学C application, but surely there is a better way?


My suspicion is that nothing in your code is creating the window. When you create a new Cocoa Xcode application, Xcode sets up an XIB with your interface for you. Open up MainMenu.xib (should be under Resources) in interface builder and delete the window that it throws in by default.


If you don't want to show a window you may consider run your application in background. That will stop the window to appear.

In order to run your application in the background, set YES to "Application is background only" in your app's PLIST file


Return false in your NSDocument subclass' windowNibName method.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜