iOS Question

shouldChangeCharactersInRange is not being called.?

I have the method that has to be called to check mobile number range and other format. But this method is not being called :(

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

Answer

Did u set a delegate?

class yourViewController: UITextFieldDelegate {

}

self.yourTextField.delegate = self;