• 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: Removing submenus from a menu
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Removing submenus from a menu


  • Subject: Re: Removing submenus from a menu
  • From: Greg Hurrell <email@hidden>
  • Date: Mon, 13 Jan 2003 12:38:21 +1030

Thanks for the reply, j o a r.

I would like to trap the crash in the debugger, but for some reason, PB is not letting me run this executable in gdb! (It will let me do it with other projects or other executables, but not this one... it's a problem I've posted about before, but no answers other than re-installing PB, which didn't work)

But thanks to your confirmation that the -removeItem method is indeed the way to do this, I persisted with some copious NSLogging and established what the
problem is.

Ultimately, I found out that -removeItem doesn't only remove an NSMenuItem from an NSMenu; it actually removes it and then sends it a -release message.

In my case, I wanted to have the menu "stick around" so that I could add it back in later if necessary with a -insertItem:atIndex call. So the solution was to send the NSMenuItem a -retain before removing it to increase its retain count; and when adding it back in send a -release after the -insertItem:atIndex to reduce its retain count. In this way it's retain count is more or less stuck at 1 for the life of the program, which is effectively what I want.

In this way I can remove, add, remove, add, remove, add etc to my heart's content and there are no problems.

Cheers :-)
Greg

El Lunes, 13 enero, 2003, a las 02:51 AM, j o a r escribis:

Whay does it crash, ie. what is the reason listed in the crash log or the debugger? At least the first and second option you list below is correct in theory, and something I myself use in shipping applications - the problem would have to be something else. Some suggestions:

* Have you verified that the index is within the bounds of the item array?
* Have you verified that the item obtained is existing?
* Show us more code
* Try to reproduce the problem in a small sample app. If you can reproduce it, send the sample project to me and I'll take a look.

I suspect that you have a retain count problem, or a stale pointer somewhere. Try to trap the crash in the debugger and see where it occurs!

j o a r

On Sunday, Jan 12, 2003, at 16:59 Europe/Stockholm, Greg Hurrell wrote:

I'm grappling with NSMenus for the first time and I know how to add and remove basic items fairly easily. I also know how to add submenus (create the NSMenuItem that will contain the submenu, make the NSMenu that will be the submenu itself, set the submenu to be a submenu of the item, then insert your item into the menu).

But how do I remove them? Everything I try ends up crashing the app. I've tried the following, among other things:

// using an integer index for the NSMenuItem that I wish to remove
[theMenu removeItemAtIndex:theIndex];

and:

// using an id pointer to the NSMenuItem object I wish to remove
[theMenu removeItem:objectToRemove];
_______________________________________________
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.
_______________________________________________
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.

  • Follow-Ups:
    • Re: Removing submenus from a menu
      • From: j o a r <email@hidden>
References: 
 >Re: Removing submenus from a menu (From: j o a r <email@hidden>)

  • Prev by Date: Re: Release nib when file's owner is deallocated
  • Next by Date: Force logout, but run logout hook
  • Previous by thread: Re: Removing submenus from a menu
  • Next by thread: Re: Removing submenus from a menu
  • Index(es):
    • Date
    • Thread