限制用户可以输入多个UITextViews的字符数

时间:2014-08-12 19:22:59

标签: ios uitextview uitextviewdelegate

从某种意义上说,Limit number of characters in uitextview已经回答了这个问题。但我的具体情况是我在同一个ViewController中有多个textview。所以我不确定如何解决这个问题。说我只有两个textViews。我该如何处理这些案件:

  • 他们都有相同的字符限制?

  • 每个人都有不同的角色限制?分别说300和400。

我使用IBAction吗?如果是的话怎么样?

1 个答案:

答案 0 :(得分:1)

因此,您需要两个文本视图的IBOutlet

@property (weak, nonatomic) IBOutlet UITextField *textfield1;
@property (weak, nonatomic) IBOutlet UITextField *textfield2;

然后在你的委托方法

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text

您只需添加对右侧文本字段的检查

if (self.textfield1 == textfield) {
// handle first text field here

} else {
// handle second text field here
}