gpt4 book ai didi

ios - xcode 将不同的最大字符长度设置为不同的 TextField

转载 作者:行者123 更新时间:2023-11-28 22:35:55 24 4
gpt4 key购买 nike

我有两个文本框。使用this将最大字符设置为文本字段效果很好。我如何检查使用了哪个文本字段,以便设置不同的最大长度?

最佳答案

我认为您正在尝试为您的文本字段设置不同的最大字符长度,然后首先在标题中为您的文本字段创建 socket ,

//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
}
}

编辑您还可以为您的文本字段设置标签并使用它,例如switch(textField.tag)

关于ios - xcode 将不同的最大字符长度设置为不同的 TextField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16036521/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com