Re: How do I delete NSCollectionView item on right click?
Re: How do I delete NSCollectionView item on right click?
- Subject: Re: How do I delete NSCollectionView item on right click?
- From: Graham Cox <email@hidden>
- Date: Sat, 1 Aug 2009 16:20:11 +1000
On 01/08/2009, at 4:12 PM, Graham Cox wrote:
I've got an NSCollectionView with the prototype view subclassed and
I'm overriding menuForEvent. I'm creating a menu that has Edit/
Delete and when the user clicks Delete I want to remove that
collection view item. Where would you put the selector for the
Delete menu item, and how would you know when it gets called what
collection view item to delete?
By "selector" I assume you mean e.g. a -delete: IBAction method.
That would go in the controller that is handling the view. To ensure
it gets called, you simply ctrl-drag a connection from the menu item
to the controller and choose this method. Verify it gets called
using NSLog or the debugger.
Forgot to mention - if you are setting up the menu programmatically,
you need to set the target of the menu item to the controller and the
action method selector to the -delete: IBAction (it doesn't strictly
need to be an IBAction in this case, but personally I find that
declaring it as such is useful for managing the code and converting it
to an IB-based solution later).
If your menu is simple and not dynamic - i.e. it never changes
according to the state of the item it's attached to - you might find
it easier to set it up in IB rather than overriding -menuForEvent: -
just create a menu object and connect it to the 'menu' outlet of the
view.
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden