I have two UITextfields.
- First UITextfield – Minimum value = 1 and maximum value = not fixed
- Second UITextfield – Minimum value = 0 and maximum value = 99
I tried using the following :
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSUInteger newLength = [textField.text length] + [string length] - range.length;
bool kCheck = NO;
if([textField isEqual:txtDiscount])
{
if(newLength>2)
{
kCheck = NO;
}
else
kCheck = YES;
}
return kCheck;
}
But control does not fall in the if([textField isEqual:txtDiscount]) condition.
It’s not working because you’re comparing two
UITextFieldobjects to each other, rather than the strings they contain. CallingisEqualis the correct idea, but you’re calling it on the wrong things.I think what you wanted to write was this:
i.e. you need to pull out the text properties to compare to each other.