I am using following textfield delegate
to validate user entry.
Lets assume that currentTotal
equals 30.00
dollars and whenever user enters two times
equal or bigger than currentTotal
and I am trying to issue an alert.
While I am testing the application, when user enters 63
dollars, no alert happens, but as long as user enters 630
dollars then alert is issued.
tip
and currentTotal
are double
.
What am I doing wrong, any suggestions?
- (BOOL)textField:(UITextField *)aTextField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if ([aTextField.text containsString:@"$"])
{
tip = [[aTextField.text stringByReplacingOccurrencesOfString:@"$" withString:@""] doubleValue];
}
else
{
tip = [aTextField.text doubleValue];
}
if(tip > currentTotal *2)
{
[self presentViewController:[AppConstant oneButtonDisplayAlert:@"Error" withMessage:@"Please enter valid tip"] animated:YES completion:nil];
}
return YES;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField {
self.tipTF.text = @"$ ";
}