-2

I have 2 UITextViews on a single View Controller. They have placeholders in each and I'm trying to get the placeholder to disappear when the textViewShouldBeginEditing. I've tried using tags, but the first one will work, then each selection after that fails to destroy the placeholders. Thanks

TomG103
  • 311
  • 2
  • 26

3 Answers3

2

just do like this

-(void)textViewDidBeginEditing:(UITextView *)textView
{
    if([textView.text isEqualToString:@"Enter Text here......"]) //Enter Text here...... is your placeholder text
    {
        textView.text = @"";
    }
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
    if([textView.text length] == 0)
    {
        textView.text = @"Enter Text here......";
    }
}
Noor
  • 2,071
  • 19
  • 28
  • Normally I would do that. The issue for me is that they have different placeholders of NSMutableAttributedString types. – TomG103 Feb 04 '15 at 20:38
  • I also like putting this in shouldChange textInRange if textView.text.length == 1 && text == "" { textView.attributedText = textView.placeHolder textView.selectedRange = NSMakeRange(0, 0) – hidden-username Feb 04 '15 at 20:40
0

Instead of using

-(BOOL)textViewShouldBeginEditing:(UITextView *)textView

I used

-(void)textViewDidBeginEditing:(UITextView *)textView

and it works fine now. Thanks for the help all.

TomG103
  • 311
  • 2
  • 26
-2

Use if textView.isFirstResonder, but do it in

textViewDidBeginEditing

not in

textViewShouldBeginEditing
hidden-username
  • 2,610
  • 3
  • 14
  • 19
  • This doesn't classify as an answer. If another answer is incorrect, state that it is so that it can be removed or fixed. The purpose is to provide clear correct answers for not only the OP, but also for any others who might have similar problems – CaptJak Feb 04 '15 at 20:55
  • That's not working either. I tried using tags and if tag = 1 else if tag = 2 and that fails as well. – TomG103 Feb 04 '15 at 20:56