Re: NSTextField has cursor in it?
Re: NSTextField has cursor in it?
- Subject: Re: NSTextField has cursor in it?
- From: "Louis C. Sacha" <email@hidden>
- Date: Fri, 5 Dec 2003 21:43:15 -0800
Hello...
As another poster (Ed) pointed out, getting the firstResponder from
the window does not work because it returns the shared text editing
object, not the actual object that is being edited.
Have you tried the suggestion from my previous post in this thread?
Try using the NSControl instance method currentEditor (NSTextView is
a subclass of NSControl).
- (NSText *)currentEditor
If the receiver is being edited -- that is, it has an NSText object
acting as its field editor, and is the first responder of its
NSWindow -- this method returns the NSText editor; otherwise, it
returns nil.
Specifically, this means that if the response to calling this method
on one of your NSTextField instances is not nil, then that
NSTextField is the one currently being edited...
For example. you could add something similar to the following method
to your controller class to get the currently editing NSTextField (or
nil if none of them are currently being edited)
/* myFirstTextField, mySecondTextField, and
myStillYetAnotherTextField are your outlets to the NSTextFields that
you have as (IBOutlet) instance variables of your controller class
and connecting in Interface Builder*/
- (NSTextField *)currentTextField
{
if ([myFirstTextField currentEditor])
{
// myFirstTextField is the NSTextField that is currently being edited
return myFirstTextField;
}
if ([mySecondTextField currentEditor])
{
// mySecondTextField is the NSTextField that is currently
being edited
return mySecondTextField;
}
if ([myStillYetAnotherTextField currentEditor])
{
// myStillYetAnotherTextField is the NSTextField that is
currently being edited
return myStillYetAnotherTextField;
}
return nil; // none of your NSTextFields are currently being edited
}
Hope that helps,
Louis
So are you saying that the code is correct and if not then what is wrong with
it?
Here is my take...
this line is giving me problems
id firstResponder = [self myWindow] firstResponder];
when I changed it to this it worked
id firstResponder = [myWindow firstResponder];
however the firstResponder is not a NSTextView because my curson is in a
text field thus when I tried to equate it as given
if (firstResponder == myTextField)
it does not work because firstResponder is a NSTextView and myTextField in a
NSTextField
is there any way to resolve this dilemma?
thanks in advance
_______________________________________________
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.