2009-05-26 64 views
1

我有一個觀點,我想的功能是這樣的..如何立即計算在iphone中輸入uitextfield?

第一的UITextField是價格爲前10000 第二的UITextField PRECENTAGE爲前70

第三的UILabel這將顯示爲前$結果7,000.00

我想這也是我只要一輸入7的結果標籤上應顯示$ 700.00

回答

3

作出反應,每按一次鍵,實現UITextFieldDelegate尤其是文本框:shouldChangeCharactersInRange:replacementString:方法,並將其設置一個是priceField和percentageField的代表。精神上的東西:

- (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]; 
} 
+0

這是不是在我身邊工作,而且應該更改字符在你不返回「真」或「假」錯誤在這裏產生? – 2014-08-07 14:15:24