gpt4 book ai didi

ios - shouldChangeCharactersInRange 没有被调用。?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:55:48 26 4
gpt4 key购买 nike

我有必须调用的方法来检查手机号码范围和其他格式。但是这个方法没有被调用:(

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
ProfileBasicCell *cell=[_tblView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
if (cell.txtMobile.text== textField && string.length>0) {
NSString *newText=[textField.text stringByReplacingCharactersInRange:range withString:string];
if (newText.length<=15) {
if (newText.length==4 || newText.length==8) {
textField.text=[newText stringByAppendingString:@"-"];
return NO;
}
return YES;
} else {
return NO;
}
}
return YES;
}

最佳答案

你设置委托(delegate)了吗?

class yourViewController: UITextFieldDelegate {

}

self.yourTextField.delegate = self;

关于ios - shouldChangeCharactersInRange 没有被调用。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40677054/

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