Re: Trying again: how to implement textShouldEndEditing for NSTableView?
Re: Trying again: how to implement textShouldEndEditing for NSTableView?
- Subject: Re: Trying again: how to implement textShouldEndEditing for NSTableView?
- From: Greg Titus <email@hidden>
- Date: Fri, 22 Jun 2001 15:58:11 -0700
On Friday, June 22, 2001, at 01:54 PM, Matt Ridley wrote:
I seem to have solved the problem, but I'm not entirely sure why my
original
code doesn't work. The NSTableView documentation says I should implement
this method:
- (BOOL)textShouldEndEditing:(NSText *)textObject
Ah, but the NSTableView documentation says that you could implement it
if you are a subclass of NSTableView, _not_ if you are a table view's
delegate.
What is going on here is that when you edit a table cell the NSTableView
puts an NSTextView into the space where the cell goes in order to
actually perform the editing (this is the window's "field editor" - see
the NSWindow documentation for details).
The NSTableView sets _itself_ up as the delegate for the NSTextView so
that the table gets notified when editing ends and how and so on so that
it can tell you that a table value changes, select the next cell
appropriately, and so on. You are the delegate of the table, which is
the delegate of the text view. So if you were the table (a subclass of
NSTableView) then you could implement any or all of the text delegate
methods described in the NSTextView documentation, but as it is, your
object doesn't get them directly.
But that doesn't work, as I said. So, I looked up the NSControl
documentation, and instead implemented its equivalent method in my table
delegate:
- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText
*)fieldEditor
Which does indeed work as desired. Now all I need is to understand why
the
first method doesn't work. :-) Any thoughts would be appreciated!
The second method works because the table view is kind enough to forward
along the delegate message it is getting from the text view on to your
delegate object using the control:textShouldEndEditing: method. The
reason for the method name change (obviously) is so that your delegate
can be informed of which control the text view field editor is acting on
behalf of.
(I was going to write this stuff before about your original question,
but you figured it out yourself too quickly.) :-)
Hope this helps,
--Greg