1

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?

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

Do I use IBAction? If yes how?

Community
  • 1
  • 1
learner
  • 11,490
  • 26
  • 97
  • 169

1 Answers1

1

So you need IBOutlet for both textviews

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

then in your delegate method

- (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
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • If you didn't want to keep the textViews as properties for whatever reason, you could also use tags. `textView1.tag = 1; textView2.tag = 2; if (textView.tag == 1) { // do something } else { // do something else }` – Vadoff Aug 12 '14 at 21:01