views:

190

answers:

1

i have a view and i want functionality something like this..

first UITextfield is price for ex- 10000 second UItextField precentage for ex-70

third UIlabel which will show the result for ex- $ 7,000.00

i want this and also as soon as i type 7 the result label should show $ 700.00

+1  A: 

To react to each key press, implement UITextFieldDelegate and especially textField:shouldChangeCharactersInRange:replacementString: method and set it as a delegate for both priceField and percentageField. Something in the spirit 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];
}
tequilatango