Re: Grabbing key presses in NSTableView
Re: Grabbing key presses in NSTableView
- Subject: Re: Grabbing key presses in NSTableView
- From: Bill Cheeseman <email@hidden>
- Date: Tue, 27 Apr 2004 12:28:17 -0400
on 2004-04-27 11:29 AM, matt neuburg at email@hidden wrote:
>
On Wed, 21 Apr 2004 09:52:04 +0200, "Kasper J. Jeppesen"
>
<email@hidden> said:
>
> I need to let my user delete records from a tableview simply by
>
> pressing backspace. The only clues i have been able to find, towards
>
> doing this, involves subclassing NSTableView. Is that really the only
>
> way?
>
>
>
> Lots of applications do this, so I would almost asume cocoa has some
>
> really neat way of doing it (like so many other things in cocoa)... any
>
> clues?
>
>
That's how I do it - subclass NSTableView and implement keyDown: (and notify
>
the delegate). Why is this approach undesirable or non-"neat"? m.
I do it differently -- but I don't have my code handy, so I'll have to
describe my technique from memory. I consider my technique "neater" only
because it makes good use of IB and requires less writing of code.
1. Add a button to your window in IB (and hide it if you don't want to have
a button separate from the table, although I think the usual "+" and "-"
buttons adjacent to table views constitute good design).
2. Assign the Delete key equiv. to the button in IB.
3. Write a -deleteRow: action method, and connect it to the button in IB.
4. Write the -deleteRow: action method so that it removes the selected row's
array element from the table view's datasource, and update the table view.
5. Press Delete and watch the row disappear!
Alternatively (or in addition), add a menu item to delete a row. Just use IB
to add the menu item and assign it the Delete key equiv., then connect the
same action method to the menu item.
In general, whenever I'm looking to accomplish something with a keystroke, I
think about key equivalents for menu items and buttons before I think about
subclassing a view and implementing -keyDown:.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
_______________________________________________
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.