I suspect that you must have some line of code that is modifying modifiedFieldText
before you get to this line. You should make sure that the range
is applied to the original textField
contents, achieved by making the stringByReplacingCharactersInRange
use the textfield
directly, such as:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSString *modifiedFieldText = [textField.text stringByReplacingCharactersInRange:range withString:string];
// now do whatever else you want
}
With that code, if the text field contained $1,234,567.00
and the user deleted the 5
, the range would be {7, 1}
, and the resulting modifiedFieldText
would be $1,234,67.00
, which you can presumably proceed and reformat to adjust the punctuation as you see fit.
If you are still having troubles, update your question with a more complete rendition of your shouldChangeCharactersInRange
.