Issue:
When updating the .text property of a UITextField object inside of a text change listener an infinite loop occurs. It appears that I'm illegally modifying the object even though edit mode is turned on. I log the value of .text, after the edit occurs, and notice it prints numbers in base 2 (2 4 8 16 32) until it seems to occupy the max int value and then just prints 0s but loops infinitely.
Synopsis:
I am attempting to format user text in a user text field as it is inputted. Users are only allowed to type in whole numbers, I use the number keypad. I would like to format the text such that after two digits it automatically inserts a decimal, similar to how atm's format amounts entered and automatically insert a decimal.
Attempted to:
I have attempted to do the following (both with the same reaction):
1. Register a selector to the UITextFieldTextDidChangeNotification, process my input, and update the value.
2. Use interface builder, tie an ibaction to the editing changed event for the uitext field
Both end with the same result
Code Snippet (sorry for the messy code, last attempt was creating new object in memory and attempting to reference that, sorry I didn't release my temp objects):
Thanks for any assistance
[edited, sorry placed old code in block]
When updating the .text property of a UITextField object inside of a text change listener an infinite loop occurs. It appears that I'm illegally modifying the object even though edit mode is turned on. I log the value of .text, after the edit occurs, and notice it prints numbers in base 2 (2 4 8 16 32) until it seems to occupy the max int value and then just prints 0s but loops infinitely.
Synopsis:
I am attempting to format user text in a user text field as it is inputted. Users are only allowed to type in whole numbers, I use the number keypad. I would like to format the text such that after two digits it automatically inserts a decimal, similar to how atm's format amounts entered and automatically insert a decimal.
Attempted to:
I have attempted to do the following (both with the same reaction):
1. Register a selector to the UITextFieldTextDidChangeNotification, process my input, and update the value.
2. Use interface builder, tie an ibaction to the editing changed event for the uitext field
Both end with the same result
Code Snippet (sorry for the messy code, last attempt was creating new object in memory and attempting to reference that, sorry I didn't release my temp objects):
Code:
- (IBAction) atmFormatListener:(id)sender{
UITextField *field = (UITextField*)sender;
NSNumberFormatter *decimalFormatter = [[NSNumberFormatter alloc] init];
[decimalFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[decimalFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber *number = [[NSNumber alloc] initWithInt:[field.text intValue]];
field.text = [decimalFormatter stringFromNumber:number];
}
Thanks for any assistance
[edited, sorry placed old code in block]