Albert Zhang
Albert Zhang

Reputation: 777

textViewShouldBeginEditing not called when not editable become to editable

I encountered a problem on the UITextFieldDelegate, anyone can help me will be great appreciate. There is a UITextView, and I implemented its delegate. Normally all delegate methods called very good. But in this case:

  1. set the UITextView not editable.
  2. long-press the UITextView until the popup appear (copy, cut, ...).
  3. dismiss the popup, and set the UITextView editable
  4. tap the UITextView to make the UITextView enter editing mode.
  5. you will find the delegate method textViewShouldBeginEditing not called.

I need the textViewShouldBeginEditing be called to handle some UI changes. Anyone knows how to solve it? Thanks very much!

Test project: I created a simple test project which will NSLog the calls of the methods, you can test my case quickly, thanks! The source code is here: http://goo.gl/tGQS5

Upvotes: 5

Views: 3716

Answers (2)

Zhang
Zhang

Reputation: 11607

Did you perhaps forgot to go:

myTextView.delegate = self;

?

Extra Information

In a recent app I released, I did something similar.

I disabled a UITextField so I could use a long press gesture on a UITableViewSectionHeader to edit the section header's name, and single tap section header to select it.

I had to put:

// groupName is my UITextField
groupName.userInteractionEnabled = YES;
[groupName becomeFirstResponder];

In my long press gesture recognizer callback method.

Upvotes: 7

Srikanth
Srikanth

Reputation: 1930

@Albert Zhang, "textViewShouldBeginEditing" will be called only when your textview becomes first responder. You can force it by doing the following.

- (IBAction)onSwitch:(id)sender{
    self.textView.editable = self.editableSwitch.on;

    if(self.textView.editable)
    {
        [[self textView]becomeFirstResponder];
    }
}

Upvotes: 0

Related Questions