2012-09-01 153 views

回答

3

是的。设置你的文本字段的委托,然后实现下面的方法:

- (BOOL)textField:(UITextField *)tf shouldChangeCharactersInRange:(NSRange)r replacementString:(NSString *)str 
{ 
    if (tf == theTextFieldYouWannaBehaveLikeThis) { 
     if ([str isEqualToString:@","]) { 
      return NO; 
     } 
    } 
    return YES; 
} 
+0

是的,但如果我现在我从用户界面委托,我所有的UItextFields有这个,即使只有1个必须有(其他人有不同的功能) – Alessandro

+0

@Alessandro你为什么认为发送者文本字段作为第一个参数传递自己?您可以检查它是否与特定文本字段相同。 (见编辑) – 2012-09-01 18:17:34

0

有一个UITextField一个keyboardType属性:

typedef enum { 
    UIKeyboardTypeDefault,    // Default type for the current input method. 
    UIKeyboardTypeASCIICapable,   // Displays a keyboard which can enter ASCII characters, non-ASCII keyboards remain active 
    UIKeyboardTypeNumbersAndPunctuation, // Numbers and assorted punctuation. 
    UIKeyboardTypeURL,     // A type optimized for URL entry (shows ./.com prominently). 
    UIKeyboardTypeNumberPad,    // A number pad (0-9). Suitable for PIN entry. 
    UIKeyboardTypePhonePad,    // A phone pad (1-9, *, 0, #, with letters under the numbers). 
    UIKeyboardTypeNamePhonePad,   // A type optimized for entering a person's name or phone number. 
    UIKeyboardTypeEmailAddress,   // A type optimized for multiple email address entry (shows space @ . prominently). 

    UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, // Deprecated 

} UIKeyboardType;