Re: NSTextField value changes after tab-through
Re: NSTextField value changes after tab-through
- Subject: Re: NSTextField value changes after tab-through
- From: Yann Bizeul <email@hidden>
- Date: Mon, 4 Jun 2007 22:56:23 +0200
I have an app with several NSTextFields (the single-line kind you
can type in) that are initially set to an empty string (@"").
Later in my program, I try to check whether or not the field is
empty using the IF statement:
I think you should not do that. since the field is already "empty"
if( [textField stringValue] == @"" )
// do something
if( [textField stringValue] == nil)
// do something
as you can see, this do not seem to be reliable :-) I think the
regular stringValue of an empty text field is nil but I'm not sure,
if this is the case, you should be carefll when setting its value to
set nil and not @"" when the string is empty
Personally, I like to use [[textField stringValue]length] . this will
return 0 if stringValue is nil or empty. quite reliable.
if( [textField isEmpty] ) // this one crashes, just thought I'd
eliminate it as a possibility
// do something
Well, since this is a NSBezierPath method, I'm not suprised :-) (no
yellow triangle ? time to re-enable warnings, or cast correctly :-)
Any other advice guys ?
Yann Bizeul - yann at tynsoe.org
Cocoa Developer
Tynsoe Projects
BuddyPop - GeekTool - SSH Tunnel Manager - ...
http://projects.tynsoe.org/
Le 4 juin 07 à 22:43, Matthew Stone a écrit :
Dearest Cocoa users,
I have an app with several NSTextFields (the single-line kind you
can type in) that are initially set to an empty string (@"").
Later in my program, I try to check whether or not the field is
empty using the IF statement:
if( [textField stringValue] == @"" )
// do something
This returns true on any fields that have not changed AND have not
had the cursor placed on them, either by clicking on the field or
by tabbing through them. I have tried checking if it's empty as I
said above, plus:
if( [textField stringValue] == nil)
// do something
if( [textField isEmpty] ) // this one crashes, just thought I'd
eliminate it as a possibility
// do something
I noticed that there is a task of - textDidChange but that only
lets me know if the text *changed* an not whether or not the field
is still empty. I've also tried to NSLog() the strings before and
after they've been tabbed-through and the output is the same. One
of my thoughts was to output the ASCII values of the characters in
the string, but I honestly don't know how nor could I figure out
how (I'm no Cocoa expert).
So, does anyone know what, exactly, the string in the NSTextField
is after tabbing through it? And if not, does anyone know how I
can find out??
Thanks!
-M. Stone
_________________________________________________________________
Like puzzles? Play free games & earn great prizes. Play Clink now.
http://club.live.com/clink.aspx?icid=clink_hotmailtextlink2
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden