ios - shouldChangeCharactersInRange 没有被调用。?
<p><p>我有必须调用的方法来检查手机号码范围和其他格式。但是这个方法没有被调用:( </p>
<pre><code>-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
ProfileBasicCell *cell=];
if (cell.txtMobile.text== textField && string.length>0) {
NSString *newText=;
if (newText.length<=15) {
if (newText.length==4 || newText.length==8) {
textField.text=;
return NO;
}
return YES;
} else {
return NO;
}
}
return YES;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>你设置了代理吗?</p>
<pre><code>class yourViewController: UITextFieldDelegate {
}
self.yourTextField.delegate = self;
</code></pre></p>
<p style="font-size: 20px;">关于ios - shouldChangeCharactersInRange 没有被调用。?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/40677054/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/40677054/
</a>
</p>
页:
[1]