用户可以输入多个UITextViews的字符数限制 [英] limit number of characters user may enter into multiple UITextViews

查看:91
本文介绍了用户可以输入多个UITextViews的字符数限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从某种意义上说,这个问题已经在> uitextview中限制字符数.但是我的特殊情况是在同一个ViewController中我有多个textview.因此,我不确定如何解决该问题.说我只有两个textViews.我如何处理这些情况:

In some sense this question has already been answered at Limit number of characters in uitextview. But my particular case is that I have more than one textview in the same ViewController. So I am not sure how to fix that problem. Say I only have two textViews. How might I handle these cases:

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

  • they both have the same character limit?

每个字符都有不同的字符限制?分别说300和400.

each has different character limit? say 300 and 400 respectively.

我使用IBAction吗?如果是,怎么办?

Do I use IBAction? If yes how?

推荐答案

所以两个文本视图都需要IBOutlet

So you need IBOutlet for both textviews

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

然后在您的委托方法中

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

您只需为正确的文本字段添加一个支票

You simply add a check for the right textfield

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

} else {
// handle second text field here
}

这篇关于用户可以输入多个UITextViews的字符数限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆