NSTextField delegate that will monitor user input
NSTextField delegate that will monitor user input
- Subject: NSTextField delegate that will monitor user input
- From: "Huyler, Christopher M" <email@hidden>
- Date: Thu, 4 Dec 2003 17:13:56 -0500
- Thread-topic: NSTextField delegate that will monitor user input
Here's what I'm trying to do:
1) Check each character the user enters into a NSTextField to make sure
it is a number or period (for an ip address). If it is, allow it to be
entered, if it isn't, don't allow it to be entered.
2) When the user is finished, check the syntax and save it.
The problem I am having is that an NSTextField uses the Window's Field
Editor. I tried to set the Field Editor's delegate to the current
object (which is the NSTextField's delegate) but after I execute the
line [fieldEditor setDelegate:self], textShouldEndEditing never gets
called. How can I combine these two delegates to get the results I'm
looking for?
-(BOOL)control:(NSControl *)control
textShouldBeginEditing:(NSText *)fieldEditor
{
/* is this legit? */
...
[fieldEditor setDelegate:self];
return YES;
}
-(BOOL)control:(NSControl *)control
textShouldEndEditing:(NSText *)fieldEditor
{
...
return YES;
}
- (BOOL)textView:(NSTextView *)textView
shouldChangeTextInRange:(NSRange)affectedCharRange
replacementString:(NSString *)replacementString {
static const unichar kAllowed[] =
{'0','1','2','3','4','5','6','7','8','9','.','\n'};
int strItr,chrItr;
BOOL valid;
for (strItr=0;strItr<[replacementString length];strItr++)
{
valid=NO;
chrItr=0;
while ( valid == NO && chrItr < 12 )
{
if ([replacementString characterAtIndex:strItr] ==
kAllowed[chrItr])
valid=YES;
chrItr++;
}
if (valid == NO)
return NO;
}
return YES;
}
--
Christopher Huyler
Computer Associates Intl.
mailto:email@hidden
_______________________________________________
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.