Ask a Question related to Mac Programming, Design and Development.
-
Jamal Bernhard #1
Continuation of NSTextField issues
I still feel like I'm fighting things here. I have a prefs window with a
handful of text fields that should all take positive integers. Before
the prefs window is closed I must make sure all values are valid and if
not raise an alert panel and reset the invalid values to their previous
states.
Looking through several apps (photoshop, eudora, acrobat reader), it
seems text fields in prefs windows are handled in a fairly consistent
manner: the user is allowed to enter any value into the field (including
"illegal" characters) until either (a) the text field is deselected by
return, tab, mouse click, etc., or (b) the user clicks "OK" to close the
window. When either (a) or (b) happens and there is an illegal value, an
alert panel is raised.
(a) can easily be handled by the text field's action. The problem is how
to handle (b). I still do not see a way to do this without having to
poll the text fields inside the button action method before the window
is closed.
I tried implementing -controlTextDidChange but then you are forced to
error check after every keystroke which is not the behavior of the apps
above and it leads to other problems. For example, I have two text
fields that represent a range -- min and max. If the user sets the min
to 7 and then tries to set the max to 15, when the user types the "1" I
obviously do not want to treat that as an error (yet). However the user
could click on the "OK" button at this point and then I have to respond
to the illegal value in that field.
It seems like maybe I should be using NSNumberFormatter but I am having
a hard time following the documentation without any code examples, and I
can't tell if this will solve the problem of a user closing the window
while a text field is still being edited. If someone can confirm that
formatters will fix the problem, I will continue down that path.
I would like to learn a clean way to handle these situations the first
time so I don't get into bad habits.
Thanks in advance.
Jamal Bernhard Guest
-
continuation operator
What is the best way to utilize most recent continuation operator \ ? I recently copied Mac director files to PC and they have different... -
Green Background Continuation
Put the Color Settings under Edit to Full Color Management...Optimized for Prints and the background turned to pink and all opened photos are bright... -
NSTextField -- question about when actions are sent
I have a prefs window with a few NSTextFields. I am noticing two things: 1. Every time the prefs window is opened, the NSTextField that is the... -
Possible use for a continuation? [Generating all factors of agiven number]
daz wrote: Darn! I was hoping to finally get a chance to use one :-). What I was really trying to achieve, though, was to have a generic... -
Possible use for a continuation? [Generating all factors of a given number]
Harry Ohlsen <harryo@qiqsolutions.com> wrote: Overkill - this should do it: class MultiCounter def initialize(a, b = nil) @max = a @min =... -
Jamal Bernhard #2
Re: Continuation of NSTextField issues
Tom Harrington <tph@pcisys.no.spam.dammit.net> wrote:
Only because polling all values seemed like a brute force method to me> Is there some reason you don't want to just check the values when the
> user clicks "OK", and only close the window if they're valid?
and I was looking for something cleaner, and in my first post on the
subject I received more than one comment stating that I should make
better use of the AppKit.
Jamal Bernhard Guest
-
Tom Harrington #3
Re: Continuation of NSTextField issues
In article
<jamalbspambegone-1E1E15.23251815082003@news.sf.sbcglobal.net>,
Jamal Bernhard <jamalbspambegone@pacbell.goawayspam.net> wrote:
It's frequently best to let GUI widgets tell you what to do, by> Tom Harrington <tph@pcisys.no.spam.dammit.net> wrote:
>>> > Is there some reason you don't want to just check the values when the
> > user clicks "OK", and only close the window if they're valid?
> Only because polling all values seemed like a brute force method to me
> and I was looking for something cleaner, and in my first post on the
> subject I received more than one comment stating that I should make
> better use of the AppKit.
listening for appropriate delegate callbacks, notifications, etc. But
this can be taken too far. In the case of a window where the user's
filling in NSTextFields, and clicking an "OK" button when done, there's
nothing wrong with just asking all the text fields for their current
value at the time the button is pressed.
--
Tom "Tom" Harrington
Macaroni, Automated System Maintenance for Mac OS X.
Version 1.4: Best cleanup yet, gets files other tools miss.
See [url]http://www.atomicbird.com/[/url]
Tom Harrington Guest
-
Jamal Bernhard #4
Re: Continuation of NSTextField issues
Tom Harrington wrote:
Ok -- thanks a lot for the feedback...>>>Only because polling all values seemed like a brute force method to me
>>and I was looking for something cleaner, and in my first post on the
>>subject I received more than one comment stating that I should make
>>better use of the AppKit.
> It's frequently best to let GUI widgets tell you what to do, by
> listening for appropriate delegate callbacks, notifications, etc. But
> this can be taken too far. In the case of a window where the user's
> filling in NSTextFields, and clicking an "OK" button when done, there's
> nothing wrong with just asking all the text fields for their current
> value at the time the button is pressed.
Jamal Bernhard Guest



Reply With Quote

