Re: firstResponder comparison failing
Re: firstResponder comparison failing
- Subject: Re: firstResponder comparison failing
- From: Erik Buck <email@hidden>
- Date: Fri, 9 Jun 2006 16:42:30 -0400
> I figure this is part of Obj-C that I'm missing. Looking at "y", I
> see that it is an "NSTextView" type ("x" is an "NSTextField"
> type). How do I tell if "x" is a first responder/selected?
What you're getting back for y is NSTextField's field editor.
NSTextField is overriding the standard first responder methods in
order to give first responder status to its field editor rather than
itself because it does not handle input directly.
And I will go further and mention that the field editor's delegate is
the text field being edited.
Right away I am suspicious why you want to be polling your user
interface items to see which is the first responder. That seems very
suspect to me. Nevertheless, Apple even provides this example code
right in the documentation:
Listing 1 Determining if a text field is first responder
if ( [[[self window] firstResponder] isKindOfClass:[NSTextView
class]] &&
[window fieldEditor:NO forObject:nil] != nil ) {
NSTextField *field = [[[self window] firstResponder]
delegate];
if (field == self) {
// do something based upon first-responder status
}
}
Perhaps you would rather just register for the (void)
controlTextDidBeginEditing:(NSNotification *)notification notification ?
http://developer.apple.com/documentation/Cocoa/Reference/
ApplicationKit/Classes/NSControl_Class/Reference/Reference.html
http://developer.apple.com/documentation/Cocoa/Conceptual/TextEditing/
Tasks/FieldEditor.html
http://developer.apple.com/documentation/Cocoa/Conceptual/
TextArchitecture/Concepts/TextFieldsAndViews.html
http://developer.apple.com/documentation/Cocoa/Conceptual/
BasicEventHandling/Concepts/FirstResponder.html
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden