Re: Cocoa Application without any NIB
Re: Cocoa Application without any NIB
- Subject: Re: Cocoa Application without any NIB
- From: Chris Scharver <email@hidden>
- Date: Thu, 23 Oct 2003 11:54:40 -0500
On Wednesday, October 22, 2003, at 07:45 PM, Andrew Kazmierski wrote:
I'm working on an application in Cocoa that creates all of the UI
elements programmatically, and find no use for the NIB file. My
principal class is my controller, a subclass of NSApplication. The
problem is, if I delete MainMenu.nib or delete the key for a main nib
file in info.plist, the application crashes with an error due to
trying to load a nib file or the lack of a nib file. Is there any way
to override a method or something to not need any NIB files?
You'll have to define a new main() implementation. The default main.m
generated by ProjectBuilder just calls NSApplicationMain(). Looking at
<
http://developer.apple.com/documentation/Cocoa/Reference/
ApplicationKit/ObjC_classic/Classes/NSApplication.html>, it's clear
that it will always try to load a nib file. Just include the
appropriate calls to [NSApplication sharedApplication] and [NSApp run]
and you should be set.
Note that you'll have to create the menu and other basic things that
are much easier to handle in a nib file. Also, you must have your
executable packaged into an application bundle even if you are not
using a nib. Otherwise, the process cannot properly register with the
window manager, and you cannot receive user events. You can't use
AppKit from command line tools unless you jump through a few hoops. For
example, GLUT has a specific workaround to handle running non-packaged,
non-nib windowed applications from the command line.
It's doable, but in the end, it seems a lot easier to just use a nib
file. I've learned the hard way. :)
Chris
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.