【发布时间】:2018-05-07 09:31:17
【问题描述】:
我尝试将 maxlength 设置为我的 UITextfield,但它也会影响我的其他 UITextfield。
我尝试使用:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
// Prevent crashing undo bug – see note below.
if(range.length + range.location > textField.text.length)
{
return NO;
}
NSUInteger newLength = [textField.text length] + [string length] - range.length;
return newLength <= 25;
}
我只想将 maxlength 设置为特定的 uitextfield。
【问题讨论】:
-
添加支票:
if (textField == myTextField) { //what you did goes here } -
需要在文本域中添加标签,并在 shouldChangeCharactersInRange 方法中比较标签
标签: ios objective-c uitextfield