Re: NSRunAlertPanel-not working?
Re: NSRunAlertPanel-not working?
- Subject: Re: NSRunAlertPanel-not working?
- From: James McConnell <email@hidden>
- Date: Mon, 16 Feb 2004 21:47:12 -0600
On 2/16/04 9:30 PM, "Ryan Bates" <email@hidden> wrote:
>
Be careful with copy and paste! Duplicate code is a bad thing. Just
>
think, if you ever wanted to change the message in the alert dialog
>
then you would need to change it seven times. I suggest refactoring out
>
the validation check like this:
>
>
// Returns YES if field is valid
>
- (BOOL)validateTextField:(NSTextField *)textField
>
{
>
if ([[textField stringValue] isEqualToString:@""]) {
>
NSRunAlertPanel(@"Empty field", @"Please enter a value.",
>
@"OK", nil, nil);
>
return NO;
>
}
>
return YES;
>
}
>
>
You could then call this method for each field - even then you could
>
probably refactor a bit more. Also, you may want to look into using
>
Interface Builder actions instead of listening for the notifications.
>
>
Hope that helps.
>
>
Ryan
Thank you sir! Seems to work, only when the user clicks "OK", focus moves
to the next field, allowing the user to leave the previous field blank. How
would I go about returning focus to the text field after the alert panel
returns? I think this is something easily found in the docs, I'll take a
look myself.
Could you maybe expand on the Interface Builder actions you spoke of? I'm
using notifications, and I set up a NSNotificationCenter to handle all of
the notifications I have on each text field. I have a sneaking suspicion
that when one is triggered (say, on the "name" text field), that all of them
are being triggered.
Thanks again for the code, Ryan, extremely helpful!
James
_______________________________________________
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.