OGeek|极客世界-中国程序员成长平台

标题: ios - shouldChangeCharactersInRange 没有被调用。? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 12:23
标题: ios - shouldChangeCharactersInRange 没有被调用。?

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

-(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;
}



Best Answer-推荐答案


你设置了代理吗?

class yourViewController: UITextFieldDelegate {

}

self.yourTextField.delegate = self;

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






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4