Re: Delegate methods not working...
Re: Delegate methods not working...
- Subject: Re: Delegate methods not working...
- From: James McConnell <email@hidden>
- Date: Sat, 06 Mar 2004 09:56:53 -0600
On 3/5/04 11:36 PM, "Ryan Bates" <email@hidden> wrote:
>
It appears "control:textShouldEndEditing:" only gets called if the user
>
attempts to leave the text field *after* he has started editing the
>
text field. This means, if you edit the text, then erase it all and
>
attempt to leave, the delegate method will be called. I played around
>
with this quite a bit and can't find a decent work around. I searched
>
quite a few places and couldn't find a solution either.
>
>
There are other validation approaches that are more user-friendly and
>
basically accomplish the same thing - however, they may require a
>
little more code. For example: after the user hits the submit button,
>
you can report an error if any of the fields are blank. You could even
>
disable the submit button until a value has been entered for each field
>
(however, some people may get confused by that).
>
>
Ryan
>
>
On Mar 5, 2004, at 7:00 PM, James McConnell wrote:
>
>
> Hey all, it's me again ;-). I have a doc based app with several text
>
> fields. In IB, I've connected each NSTextField to File's Owner
>
> (MyDocument), and set MyDocument as each fields delegate. In
>
> MyDocument.m,
>
> I've implemented the following method which checks the value of the
>
> text
>
> field. Everything compiles fine, but when I change text fields without
>
> entering an value, I do not get the NSAlertPanel like I expect. Can
>
> anyone
>
> see anything wrong? I've searched the list archives as well as
>
> cocoa.mamasam.com, and found nothing helpful.
>
>
>
> <start code>
>
>
>
> - (BOOL)control:(NSControl*)control
>
> textShouldEndEditing:(NSText*)fieldEditor
>
> {
>
> if ([[control stringValue] isEqualToString:@""])
>
> {
>
> NSRunAlertPanel(@"Empty field", @"Please enter a value.",
>
> @"OK",
>
> nil, nil);
>
> return NO;
>
> }
>
>
>
> [recipeController updateRecipe]; // simply updates a model object
>
> return YES;
>
> }
>
>
>
> <end code>
>
>
>
> Now, this is what was suggested by Ryan Bates in an earlier
>
> conversation
>
> (thanks again, Ryan!), but it's not working. I had this working with
>
> notifications, but everytime a notification was fired for one text
>
> field, it
>
> would fire every notification for all the text fields. Besides, I need
>
> notifications to do something else, and would like to get this to work
>
> so I
>
> can keep notifications for their other job. Thanks again for all the
>
> help.
>
>
>
> 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.
>
_______________________________________________
>
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.
>
Thank you once again, Ryan! Well, I've done some re-evaluating, and I've
come to the conclusion that I only need validation on one of those text
fields. The rest don't really need it. So I think I'll just go back to
Notifications to handle the validation on the text field and move on.
Thanks again, everyone!
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.