NSRunAlertPanel-not working?
NSRunAlertPanel-not working?
- Subject: NSRunAlertPanel-not working?
- From: James McConnell <email@hidden>
- Date: Mon, 16 Feb 2004 20:50:35 -0600
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. I think I have that setup, but my code is not working. Here is the
troublesome snippet. I'm sure I have something wrong here, but I just can't
tell what. Below is the notification method. Again, setting the value in
the model object works, but I can't get the alert panel to show:
*** START CODE ***
- (void)updateName:(NSNotification*)notification
{
if (![name stringValue])
{
int choice = NSRunAlertPanel(@"Empty field", @"Please enter a
value.", nil, nil, nil);
switch(choice)
{
case NSAlertDefaultReturn:
break;
case NSAlertAlternateReturn:
break;
case NSAlertOtherReturn:
break;
}
}
[recipe setName:[name stringValue]]; // If I chop out the rest of the
code, and simply use this, it works fine. It sets the value in the model
object to what is typed, and to null if nothing.
}
*** END CODE ***
Anyone care to point me in the right direction here? I have 7 text fields
to do this with, so once I get the first one working, the rest is just
copy/paste. Thanks again. BTW, I'm on OS X 10.3, but using Project Builder
as this project was started in PB and I'm not used to Xcode enough to switch
my environment on my project just yet. I know, I know, PB isn't supported,
just humor me. ;-)
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.