Re: dumb button/textfield question
Re: dumb button/textfield question
- Subject: Re: dumb button/textfield question
- From: Public Look <email@hidden>
- Date: Mon, 1 Dec 2003 22:20:01 -0500
On Dec 1, 2003, at 8:53 PM, pmcurry wrote:
>
I successfully finished a small app which has an NSButton and an
>
NSTextfield among other things. The app needs two things to run: an
>
int and a signal to start processing. My UI design was to has the user
>
enter an int into the NSTextfield, hit return, then click the
>
NSButton.
>
>
But,NOOOO! The first few times the user tried it, they enter the
>
number and clicked the button. No return in-between. Crash!
>
>
So, my question is... Can I read the value that has been entered into
>
the field without the user being required to hit return? Iguess my
>
only alternative, off the top of my head, would be to have the retrun
>
key after entering the number in the textfield be the same as the
>
button being pressed. But they made such an issue of 'I bet I could do
>
it in Swing/Java'. The user is not convinced of Cocoa/ObjC yet.
>
Favores Java.
>
It is an old NeXTism that data is not considered entered until the user
has selected another field or pressed enter. I suppose it was designed
that way. All you have to do is add the following code (taken from
Apple's docs) to the start of your your button's action.
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];
}
myWindow should be the window that contains the text field which, if
worst comes to worst, you can get by [textFiled window].
This code will end any and all editing that is in progress in myWindow
and in your case, cause the text field's action to be called.
I got this answer by searching the archives at
http://cocoa.mamasam.com/. I stumbled on a thread with great advice
about how so search for this type of information:
http://cocoa.mamasam.com/COCOADEV/2002/01/2/23251.php ;)
This difference in behavior was a common "issue" because people have
been trained that the Microsoft Windows way is the only way. There are
good reasons for the NeXT legacy behavior, but they are probably not
good enough to make it worth while to change 500,000,000 people's
expectations.
_______________________________________________
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.