Ios 未调用ShouldChangeCharactersRange。?

Ios 未调用ShouldChangeCharactersRange。?,ios,objective-c,uitextfield,Ios,Objective C,Uitextfield,我有一个方法,必须被调用来检查手机号码范围和其他格式。但未调用此方法:( -(BOOL)textField:(UITextField*)textField应更改字符范围:(NSRange)范围替换字符串:(NSString*)字符串{ ProfileBasicCell*单元格=[\u tblView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0第0节:0]]; if(cell.txtMobile.text==textField&&str

我有一个方法,必须被调用来检查手机号码范围和其他格式。但未调用此方法:(

-(BOOL)textField:(UITextField*)textField应更改字符范围:(NSRange)范围替换字符串:(NSString*)字符串{
ProfileBasicCell*单元格=[\u tblView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0第0节:0]];
if(cell.txtMobile.text==textField&&string.length>0){
NSString*newText=[textField.text stringByReplacingCharactersInRange:range with string:string];

如果(newText.length您是否设置了代理

class yourViewController: UITextFieldDelegate {

}

self.yourTextField.delegate = self;

您需要这样在控制器中设置UITextFieldDelegate

class yourViewController: UITextFieldDelegate {

}
然后,您需要以这种方式在UITextfield中指定委托

yourTextfield.delegate = self

您需要设置委托。有两种方法:

  • 通过故事板进行设置
  • 要通过故事板进行设置,请右键单击文本字段,然后将
    委托
    拖动到
    查看控制器

  • 按程序设置

  • UITextFieldDelegate添加到视图控制器,并为您的文本字段设置委托。类似这样的内容:
    self.textfield.delegate=self;

    检查您的文本字段是否设置了委托?[cell.txtMobile setDelegate:];我想在inText字段中放置的表达式没有数据源。
    yourTextfield.delegate = self