gpt4 book ai didi

iphone - 无法使用 shouldChangeCharactersInRange 隐藏键盘

转载 作者:可可西里 更新时间:2023-11-01 06:21:06 26 4
gpt4 key购买 nike

这是我的代码:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string 
{
NSCharacterSet *nonNumberSet = [[NSCharacterSet characterSetWithCharactersInString:@"אבגדהוזחטיכלמנסעפצקרשתףץםן"] invertedSet];

// max charcters
NSUInteger newLength = [textField.text length] + [string length] - range.length;
if (newLength > 14)
return NO;

// allow backspace
if (range.length > 0 && [string length] == 0) {
return YES;
}
// do not allow . at the beggining
if (range.location == 0 && [string isEqualToString:@"."]) {
return NO;
}
if ((range.location > 0) && (([[textField.text substringWithRange:NSMakeRange((range.location -1), 1)] isEqualToString:@"ף"]) || ([[textField.text substringWithRange:NSMakeRange((range.location -1), 1)] isEqualToString:@"ץ"]) || ([[textField.text substringWithRange:NSMakeRange((range.location -1), 1)] isEqualToString:@"ם"]) || ([[textField.text substringWithRange:NSMakeRange((range.location -1), 1)] isEqualToString:@"ן"])))
{
return NO;
}

// set the text field value manually
NSString *newValue = [[textField text] stringByReplacingCharactersInRange:range withString:string];
newValue = [[newValue componentsSeparatedByCharactersInSet:nonNumberSet] componentsJoinedByString:@""];
textField.text = newValue;
// return NO because we're manually setting the value
return NO;
}

我只是想做当你点击Return 键盘会消失。我不能那样做。添加到哪里以及如何添加?

最佳答案

如果您想在点击 return 键后隐藏键盘,请将以下代码添加到您的代码中:

if ([string isEqualToString:@"\n"]) {
[theTextField resignFirstResponder];
return NO;
}

希望对你有帮助

关于iphone - 无法使用 shouldChangeCharactersInRange 隐藏键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10731742/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com