Re: NSTableView edit text-field help please?
Re: NSTableView edit text-field help please?
- Subject: Re: NSTableView edit text-field help please?
- From: "Erik M. Buck" <email@hidden>
- Date: Fri, 25 Jan 2002 22:38:25 -0600
- Organization: EMB & Assocites Inc.
Once again, I am going to walk through how to find information in the
documentation not to pick on any of the individuals here but to hopefully
inform and hopefully elicit responses that will help me understand why
people are not finding information. I am interested in how and why people
find and fail to find information because I am trying to reorganize it and
improve upon it. If I ask questions like "why didn't you do this.." it is
because I really want to know why. I am not meaning to insult anyone and I
assume that whatever problems exist are more to do with the documents than
the readers.
>
If it were me, I'd look for "finish editing", "terminate editing",
>
then "end editing" before hitting on "endEditing". Since I'd
"end editing" works fine for finding the relevant information. See, you
would have found it :)
>
be searching the AppKit.pdf first, I'd be wading down through
Why not start with google (on Apple's site or not) ?
Why not use MTLIbrarian or MarshmallowLibrarian on your own disk ?
>
it to get to the right one. If it were [something else] in Foundation,
>
then I'd have to close AppKit.pdf, open Foundation.pdf, search it.
>
If it were in one of the other assorted docs, I wouldn't find it
>
until going to ADC, choosing "Advanced Search" because the regular
>
one flat doesn't work (doesn't even display a form field or let a
>
search string be entered), and then wading through the (statistically
>
expected) huge numbers of false positives to get to the right one.
>
He said he found an "endEditing" for NS Cell, but hadn't for NSWindow.
>
>
> Why didn't you read about the field editors attached to windows?...
>
>
Just because "field editor" doesn't immediately jump into mind
The point of the question and the part you clipped is that the field editor
is prominently mentioned at the top of most cell class documentation. The
field editor is mentioned in 13 different contexts within the NSCell
document including this one:
- (id)initTextCell:(NSString *)aString
Returns an NSCell object initialized with aString and set to have the cell's
default menu. If no field editor (a shared NSText object) has been created
for all NSCells, one is created.
The field editor is described in NSResponder (a superclass of all views
including the NSTableView in question).
NSControl (a superclass of every view) includes the following which should
clue a reader into the field editor:
- (BOOL)abortEditing
Terminates and discards any editing of text displayed by the receiver and
removes the field editor's delegate. Returns YES if there was a field editor
associated with the control, NO otherwise.
The field editor is mentioned at least 40 time in NSControl.
As soon as we are focused on the field editor, we get the following:
http://developer.apple.com/techpubs/macosx/Cocoa/TasksAndConcepts/Programmin
gTopics/WinPanel/Tasks/UsingWindowFieldEditor.html
Which is (surprise) in a link within NSTextFieldCell where we started.
We also find the following:
- (void)endEditingFor:(id)anObject
Forces the field editor, which anObject is assumed to be using, to give up
its first responder status, and prepares it for its next assignment. If the
field editor is the first responder, it's made to resign that status even if
its resignFirstResponder method returns NO. This forces the field editor to
send a textDidEndEditing: message to its delegate. The field editor is then
removed from the view hierarchy, its delegate is set to nil, and it's
emptied of any text it may contain.
This method is typically invoked by the object using the field editor when
it's finished. Other objects normally change the first responder by simply
using makeFirstResponder:, which allows a field editor or other object to
retain its first responder status if, for example, the user has entered an
invalid value. The endEditingFor: method should be used only as a last
resort if the field editor refuses to resign first responder status. Even in
this case, you should always allow the field editor a chance to validate its
text and take whatever other action it needs first. You can do this by first
trying to make the NSWindow the first responder:
if ([myWindow makeFirstResponder:myWindow]) {
/* All fields are now valid; it's safe to use fieldEditor:forObject:
to claim the field editor. */
}
else {
/* Force first responder to resign. */
[myWindow endEditingFor:nil];
}
Searching with "field editor end editing" finds the right documentation on
the first try...
Please, if an unfamiliar term having to do with editing is mentioned many
times prominently within every document you see when trying to find out how
to end editing, look up the field editor and find out what it is ;)