Here's the idea...
Store the string value, append to it, then use that for the operation.
Define an NSMutableString in the .h file
NSMutableString *storedValue;
@property (nonatomic, retain) NSMutableString *storedValue;
Synthesize it.
Then do this...
- (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if ([textField tag] == amountTag)
{
[storedValue appendString:string];
NSString *newAmount = [self formatCurrencyValue:([storedValue doubleValue]/100)];
[textField setText:[NSString stringWithFormat:@"%@",newAmount]];
return NO;
}
//Returning yes allows the entered chars to be processed
return YES;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…