0

当用户在文本字段上输入内容时,我使用以下方法过滤掉非数字字符:

#define NUMBERS @"0123456789"

    - (BOOL)textField:(UITextField *)textFieldBeingChanged shouldChangeCharactersInRange:(NSRange)    range replacementString:(NSString *)string
{
    NSCharacterSet *cs;
    NSString *filtered;

    // Check for period
    if ([textFieldBeingChanged.text rangeOfString:@"."].location == NSNotFound)
    {
        cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS] invertedSet];
        filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
        return [string isEqualToString:filtered];
    }

 }

但是,它也屏蔽了键盘的 Return 键,这意味着通过按“return”键,不会调用 resignFirstResponder 的代码。有什么办法可以解决这个问题?我应该如何检查是否按下了“返回”键?

谢谢

4

0 回答 0