Re: NSRunAlertPanel-not working?
Re: NSRunAlertPanel-not working?
- Subject: Re: NSRunAlertPanel-not working?
- From: Dustin Voss <email@hidden>
- Date: Tue, 17 Feb 2004 16:22:42 -0800
On 16 Feb, 2004, at 7:44 PM, mmalcolm crawford wrote:
On Feb 16, 2004, at 6:50 PM, James McConnell wrote:
Greetings, all. I have a small personal app I'm working on, and I'm
trying
to implement some user validation. I have a doc-based app with some
text
fields. No big deal. I also have an NSNotification for each field
to set a
value in a model object when focus is lost (using
NSControlTextDidEndEditingNotification). This is working fine. What
I
would like to do is check if the field is blank after it's lost
focus. If
it is, I want an alert panel telling the user they must enter a
value. I
only need it to have one "OK" button, and then return focus to the
text
field.
Rather than using notifications etc, you could implement a formatter:
<http://developer.apple.com/documentation/Cocoa/Reference/Foundation/
ObjC_classic/Classes/NSFormatter.html>
Better still, if you're using 10.3, use bindings and implement
validation methods for your model class.
Bill Cheeseman covers this topic in his "Cocoa Recipes" book (p.338).
He says that formatters aren't invoked if a field is left blank.
He implements control:textShouldEndEditing: to check if the field is
blank. If it is, he calls a method that displays the alert sheet with
two buttons: Edit and Cancel. He implements a method for the sheet's
didEndSelector, which is called when the sheet closes. He makes sure
the field is passed to the end selector. If the user closed the sheet
with the "Edit" button, he calls
[field abortEditing];
[field selectText:field];
to return focus to the field. If the user presses Cancel, he does
nothing special so that the window receives focus.
I highly recommend his book. It's full of stuff to add polish to your
app.
_______________________________________________
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.