How to calculate as soon as you type in uitextfield in iphone?
1 answer
To respond to every key press, implement the UITextFieldDelegate and especially the textField: shouldChangeCharactersInRange: replacementString: method and set it as a delegate for both priceField and percentage field. Something along the lines of:
- (void)updatePrice {
float price = [priceField.text floatValue];
float percentage = [percentageField.text floatValue];
resultLabel.text = [NSString stringWithFormat:@"$ %.2f",
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
[self updatePrice];
}
+3
a source to share