当用户在文本字段中输入内容时,我使用以下方法过滤掉非数字字符:
#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];
}
}
然而它也会阻止键盘返回键,意思是按下“返回”键 没有调用resignFirstResponder的代码。有什么办法解决这个问题?我该如何检查是否按下了“返回”键?
由于 甲