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:12:25 +1000
On 01/08/2009, at 1:11 PM, Austin Grigg 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.
To actually implement the delete, you'd use the view's -
selectionIndexes to find out what items to delete, remove them from
your data model and call the view's -setContent: with the modified
array from your model, and also remove the selection using -
setSelectionIndexes: with an empty set. You might need to call -
setNeedsdisplay:YES on the view to make it show the change.
--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