gpt4 book ai didi

iphone - 实现 shouldChangeCharactersInRange 方法时退格键不起作用 - iPhone Dev

转载 作者:太空狗 更新时间:2023-10-30 03:13:33 25 4
gpt4 key购买 nike

问题...我有一串允许的字符“0123456789”。我如何还允许键盘退格...当我从下面实现代码时...退格键不再有效...我该如何解决这个问题?

- (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { 

NSCharacterSet *nonNumberSet = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789."] invertedSet];

return ([string stringByTrimmingCharactersInSet:nonNumberSet].length > 0);

}

最佳答案

- (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSCharacterSet *nonNumberSet = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789."] invertedSet];

if (range.length == 1){
return YES;
}else{
return ([string stringByTrimmingCharactersInSet:nonNumberSet].length > 0);
}


}

关于iphone - 实现 shouldChangeCharactersInRange 方法时退格键不起作用 - iPhone Dev,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2738026/

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