我有必须调用的方法来检查手机号码范围和其他格式。但是这个方法没有被调用
-(BOOL)textFieldUITextField *)textField shouldChangeCharactersInRangeNSRange)range replacementStringNSString *)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;
}
你设置了代理吗?
class yourViewController: UITextFieldDelegate {
}
self.yourTextField.delegate = self;
关于ios - shouldChangeCharactersInRange 没有被调用。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40677054/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |