views:

157

answers:

2

Hi all,

In my application, I'm forcefully showing/hiding keyboard by making textview becomefirstresponder and resignfirstresponder and also setting textview editable YES and NO respectively.

But after hiding keyboard if I tap on textview, the keyboard doesn't show up. I'm setting textview delegate to self. And the delegate method is firing up the first time but not after that.

EDIT: I'm using the following code which I am writing for a custom button-tap and checking flags to check keyboard is in hidden state or otherwise:

switch(rotationFlag)
{
    case 0:
    {
        [self hideKeyboard];
        rotationFlag = 1;
        break;
    }

    case 1:
    {
        [self showKeyboard];
        rotationFlag = 0;
        break;
    }
}

-(void)hideKeyboard{
[txtVwForPosts setEditable:FALSE];
[txtVwForPosts resignFirstResponder];   
 }

 -(void)showKeyboard{
[txtVwForPosts setEditable:TRUE];
[txtVwForPosts becomeFirstResponder];   
 }

What is it that I'm doing wrong?

Can anybody please help? Thanx in advance.

A: 
switch(rotationFlag)
{
    case 0:
    {
        [self hideKeyboard];
        rotationFlag = 1;
        break;
    }

    case 1:
    {
        [self showKeyboard];
        rotationFlag = 0;
        break;
    }
}

-(void)hideKeyboard
{
  [txtVwForPosts resignFirstResponder];   
 }

 -(void)showKeyboard
{
  [txtVwForPosts becomeFirstResponder];   
 }
Manjunath
Not working.. After the hideKeyboard method gets called, textView tap is not detected.. only showKeyboard method on the custom button is called.
neha
I am using UITextViewTextDidBeginEditingNotification which doesn't get sent when I tap textview also textViewShouldBeginEditing: delegate method not getting called..
neha
Oh! which are all the delegates you are using?
Manjunath
for textView I'm using only UITextViewTextDidBeginEditingNotification.
neha
This is working for me. I wrote a test app for this and it is working fine... ok how are u using the switch case method?
Manjunath
On alternative button taps, I'm presenting the keyboard and hiding the keyboard for which I'm setting flags and checking them.. Now when the keyboard is hidden, it doesn't show up if tapped on textview.
neha
hey! then you should only reset the responder nothing else is needed. Tryout the edited code.
Manjunath
A: 

I'm not sure whats wrong with your code but following is a code which i wrote for same purpose:

-(IBAction)hideShowKeyboard:(id)sender
{
    if([tv isFirstResponder])
    {
        [tv resignFirstResponder];
    }
    else
    {
        [tv becomeFirstResponder];
    }
}

THis was the action for the button. and tv is the TextView outlet. But this view doesn't detect tap on the textview after the keyboard is hidden. If you want to detect taps just avoid setting the editable property to NO.

lukya
setting setEditable property to NO isn't working. Keyboard doesn't show up on tap on textview when it's hidden.
neha
Don't set editable to NO (i wrote avoid setting it to NO in the answer). Above code detects taps if [tv setEditable:NO]; is commented out.
lukya
Yes.. I meant the same thing, sorry for bad writing.. but commenting this text out isn't working..
neha
well, i changed my code and tested .. it is working fine here (i've also changed it in the answer, do try it). Have you changed the editable or userInteractionEnabled property elsewhere in your code? Also you don't need a flag as you have done in your code. isFirstResponder tells you whether the keyboard is open for that textview. Other than that, both of our codes are basically doing the same thing.
lukya