2013-04-25 63 views
0

我有兩個UITextField,用於我的應用程序,一個是價格,另一個是對產品的標籤。shouldChangeCharactersInRange影響所有的UITextField的

我已經定義二者的UITextField與@property和@synthesize到的.m

  • (BOOL)的TextField:(的UITextField *)的TextField shouldChangeCharactersInRange:(NSRange)範圍 replacementString:(的NSString *)字符串{

我用這個方法來限制價格領域的條目,但它似乎影響到現場。如何將其限制在一個領域?

回答

2

的方法,當任何UITextFields都有這個實例作爲在界面生成器或代碼委託被調用。 你可以用類似的東西來查看哪個字段叫它:

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string 
{ 
    if(textField == yourSynthesizedPropertyForPriceField) { 
     //DO SOMETHING 
    } 
    return YES; 
}