• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [NSApp mainMenu] returns nil
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [NSApp mainMenu] returns nil


  • Subject: Re: [NSApp mainMenu] returns nil
  • From: Alex Fischer <email@hidden>
  • Date: Tue, 29 Nov 2005 10:06:12 +0100

It is just what Steve is saying that lead me to do things that way. I am also not at all a Cocoa expert but think that this is possibly a bug (or undocumented feature change) introduced in 10.4.3. Personally I would like to continue the way without nibs (just because it seems possible).

I know that implementing a menu programatically seems a little bit tricky, but the point really is that it worked until 10.4.2 (and that made my life really easy).

Lets see if somebody can share some more light on what has supposed that change.

Regards


Alexander Fischer Basasoft, S.L.


On Nov 29, 2005, at 9:50 , Steve Checkoway wrote:


On Nov 29, 2005, at 12:18 AM, John C. Randolph wrote:
Let me just point out that abandoning the normal way of starting an app is a Very Bad Idea. Joar can do it, because he's an expert. There are very few situations that truly call for this, and I've never needed to do it myself in fifteen years of using NeXTSTEP and Cocoa.

Just a few points:
1. Apple docs imply that NSApplicationMain is simply a connivence function:
http://developer.apple.com/documentation/Cocoa/Reference/ ApplicationKit/ObjC_classic/Classes/NSApplication.html
In fact, they go so far as to say that it's functionally similar to


void NSApplicationMain(int argc, char *argv[]) {
    [NSApplication sharedApplication];
    [NSBundle loadNibNamed:@"myMain" owner:NSApp];
    [NSApp run];
}

This tells me that if I don't want to load a nib, then I need to call sharedApplication, and then run.

Before you say, but that the docs don't imply any such thing, I'd like to draw your attention to the "Special Considerations" subsection of that page and in particular:

Do not override sharedApplication. The default implementation, which is essential to application behavior, is too complex to duplicate on your own.

Clearly, overriding sharedApplication is a bad idea here. Where in the docs does it say that not calling NSApplicationMain is a bad idea? Nowhere that I saw and they (the docs) go so far as to provide a "functionally similar" replacement.


Lastly for this point, the same page says of the mainMenu method:

Returns the receiver's main menu.

I'm not seeing the part that says that even though a main menu is displayed, this will return nil unless NSApplicationMain is called first


Just below that, the Discussion for mainWindow clearly lays out when mainWindow will return nil.

Next point, I agree that Joar is an expert and can do this. I am not a Cocoa expert, I don't have 15 years of experience with NeXTSTEP. Instead, I'm forced to rely on the documentation. I believe that I was following the documentation. It's certainly possible that I missed something, yet I suspect that someone would have kindly pointed me to the correct doc if that were the case.

Third point, what is the correct way to start a nibless application that allows full control over the main menu?

Lastly, this would not be the first time that my particular application needed to do something that wasn't normally required irrespective of your prior experience; however, I doubt that this is one of those situations.

Lastly, are there any other undocumented consequences of not calling NSApplicationMain?

- Steve _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Re: [NSApp mainMenu] returns nil (From: "John C. Randolph" <email@hidden>)
 >Re: [NSApp mainMenu] returns nil (From: Steve Checkoway <email@hidden>)

  • Prev by Date: Re: [NSApp mainMenu] returns nil
  • Next by Date: Re: [NSApp mainMenu] returns nil under 10.4.3
  • Previous by thread: Re: [NSApp mainMenu] returns nil
  • Next by thread: How to fit an image in a webview
  • Index(es):
    • Date
    • Thread