Re: NSMenu and NSMenuItem help
Re: NSMenu and NSMenuItem help
- Subject: Re: NSMenu and NSMenuItem help
- From: Thomas Lachand-Robert <email@hidden>
- Date: Thu, 10 Jan 2002 19:21:21 +0100
Le jeudi 10 janvier 2002, ` 05:41 , Jeff LaMarche a icrit :
On Thursday, January 10, 2002, at 12:43 AM, Thomas Lachand-Robert wrote:
What is surprising? RTFM. NSMenuItem doesn't respond to itemAtIndex (it
makes sense: a menu item doesn't have pieces inside). You are confusing
with NSMenu. Why do you cast that way to NSMenu* BTW ? Certainly the
compiler has warned you that putting an NSMenu* in an NSMenuItem* is
incorrect: read the warnings, and read the doc, too. Similarly the
assignment to appMenu is incorrect.
Thank you for your assumption that I didn't read the manual. Now, let's
discuss the problem and the reality, because I did not post a question
without reading, I spent several hours trying to figure this out. The
compiler was NOT warning, and an NSMenu CAN contain NSMenus (submenus) as
well as NSMenuItem. Perhaps you should have RTFM before you responded.
No it cannot. From NSMenu:
Inherits from:
NSObject
Conforms to:
NSCoding
NSCopying
NSObject (NSObject)
-(void)insertItem:(id <NSMenuItem>)newItem atIndex:(int)index
-(id <NSMenuItem>)itemAtIndex:(int)index
NSMenu doesn't conform to protocol NSMenuItem (only the class NSMenuItem
does), so NSMenu cannot contain NSMenus. For NSMenu to have submenu, it
must have some NSMenuItem having submenus.
So, instead of berating me, perhaps you could tell me why the compiler is
telling me that I have pulled down an NSMenuItem * when NSLog is telling
me I've pulled down an NSMenu? Or why I get a runtime error but not a
compiler warning (yes, even without the cast). Certainly the item at
index 0 of my main application menu is the Apple menu, which is an NSMenu
and not an NSMenuItem. And if you don't know the answer, kindly say
nothing because I don't need crap from self-righteous people, which
fortunately there are not a lot of on this list.
The run-time error is significant here. I don't know for the NSLog, I
would need to read the exact NSLog statement to get an idea.
Anyway I gave you a solution that works for me, and S. Sudre gave a
similar one in another message.
Thomas Lachand-Robert
********************** email@hidden
<< Et le chemin est long du projet ` la chose. >> Molihre, Tartuffe.