【发布时间】:2013-04-16 12:02:23
【问题描述】:
我有两个文本字段。使用this 将最大字符设置为文本字段非常有用。 我如何检查使用了哪些文本字段,以设置不同的最大长度?
【问题讨论】:
标签: ios objective-c cocoa-touch uitextfield
我有两个文本字段。使用this 将最大字符设置为文本字段非常有用。 我如何检查使用了哪些文本字段,以设置不同的最大长度?
【问题讨论】:
标签: ios objective-c cocoa-touch uitextfield
我认为您正在尝试为您的文本字段设置不同的最大字符长度,然后首先在标题中为您的文本字段创建出口,
//header
IBOutlet UTtextField *textField1;
IBOutlet UITextField *textField2;
希望你已经做到了。
然后只检查实现方法中的textField,我将修改答案为:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if(textField == textField1) {
NSUInteger newLength = [textField.text length] + [string length] - range.length;
return (newLength > 25) ? NO : YES;
}
else if(textField == textField2)
{
//do the same with different values
}
}
编辑您还可以为您的 TextFields 设置标签并加以利用,例如 switch(textField.tag)。
【讨论】: