• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Delegate methods not working...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Delegate methods not working...


  • Subject: Re: Delegate methods not working...
  • From: Ryan Bates <email@hidden>
  • Date: Fri, 5 Mar 2004 21:36:39 -0800

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.


  • Follow-Ups:
    • Re: Delegate methods not working...
      • From: James McConnell <email@hidden>
References: 
 >Delegate methods not working... (From: James McConnell <email@hidden>)

  • Prev by Date: Re: Delegate methods not working...
  • Next by Date: NSInputStream getBuffer:length:
  • Previous by thread: Delegate methods not working...
  • Next by thread: Re: Delegate methods not working...
  • Index(es):
    • Date
    • Thread