Re: NSTableView behavior changes
Re: NSTableView behavior changes
- Subject: Re: NSTableView behavior changes
- From: Matt Neuburg <email@hidden>
- Date: Wed, 18 Mar 2009 08:22:02 -0700
- Thread-topic: NSTableView behavior changes
On Tue, 17 Mar 2009 17:00:54 -0700, Harry Plate <email@hidden> said:
>Graham,
>
>Finally getting back to this problem.
>
>>> 2) I would like my user to be able to select a table entry, and
>>> be able
>>> to respond to the 'delete' key - by discarding the selected entry.
>>> Currently
>>> that does not work at all.
>>
>> You have to make this happen yourself. The controller that is handling
>> the tableview will need to respond to the delete key by finding the
>> current selection (i.e. calling -selectedRowIndexes on the tableview),
>> deleting the corresponding items from the data model and reloading the
>> table view.
>>
>> To respond to the delete key, the controller will need to subclass
>> NSResponder and insert itself as the next responder to the table view
>> by calling [tableView setNextResponder:self]; . It then needs to
>> override -deleteBackward: or whatever.
>
>So far I have tried to accomplish this without success.
>
>1) I defined my controller class:
> @interface MCController : NSResponder
>
>2) I then defined (void)deleteBackward:(id)
>
>3) in -awakeFromNib, I set my controller as 1st responder:
>
> [sourceTableView setNextResponder:self]
Instead of 2, define keyDown and check to see if ([[theEvent characters]
isEqualToString: @"\177"]).
Also be careful in (3); this is a linked list, so when you insert yourself
into the chain you are responsible for not breaking it.
Furthermore, you probably don't want to be the table view's responder,
because now you are between the table view and its scroll view. You probably
want to be the scroll view's responder. So:
NSResponder* r = [[sourceTableView enclosingScrollView] nextResponder];
[[sourceTableView enclosingScrollView] setNextResponder: self];
[self setNextResponder: r];
Finally, make sure everything is getting hooked up and instantiated
correctly.
m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.tidbits.com/matt/default.html#applescriptthings
_______________________________________________
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