我有必须调用的方法来检查手机号码范围和其他格式。但这个方法没有被调用:(
-(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/