views:

56

answers:

1

I'm trying to format an UITextField as user types text, for instance to show separator for thousands.

I found this web page : http://www.iphonedevsdk.com/forum/iphone-sdk-development/16512-trying-add-commas.html

It seems that shouldChangeCharactersInRange: is not a good solution. I thought of a custom UIView where the view would be updated as the user types digits, yet it would require recreating the wheel...

A: 

I believe UITextView has a callback that fires everytime there is a change to its contents, then you can run the whole contents through a formatter. EDIT: Right, found the Docs Here The UITextViewTextDidChangeNotification

Should be easy enough to implement, however, a heads up, when the user types in a reasonable amount of text every keystroke will call your piece of code, i suggest making some sort of a diff between text previously checked and new text, otherwise you'll be checking a huge block of text on every keystroke (You could add a time delay for example?)

Yarek T