Re-Apply currency formatting to a UITextField on a change event
- by Jim Aldes
Howdy all,
I'm working with a UITextField that holds a localized currency value. I've seen lots of posts on how to work with this, but my question is: how do I re-apply currency formatting to the UITextField after every key press?
I know that I can set up and use a currency formatter with:
NSNumberFormatter *currencyFormatter = [[NSNumberFormatter alloc] init];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
...
[currencyFormatter stringFromNumber:...];
but I don't know how to hook it up.
For instance, if the value in the field reads "$12,345" and the user taps the "6" key, then the value should change to "$123,456".
Which callback is the "correct" one to do this in (should I use textField:shouldChangeCharactersInRange:replacementString: or a custom target-action) and how do I use the NSNumberFormatter to parse and re-apply formatting to the UITextField's text property?
Any help would be much appreciated! Thanks!