4

I have an UITextView that should become the first responder (display the keyboard) when the controller loads. The only thing is, that I have 'inflated' two UIView which each contain an UIButton. The touch events on these buttons do work when the UITextView is not yet the first responder, but after the UITextView becomes the first responder, the UIButtons are not responding to any tap-events..

How do I make sure the buttons still work when the textview becomes the first responder?

Rui Peres
  • 25,741
  • 9
  • 87
  • 137
Terrabythia
  • 2,031
  • 3
  • 19
  • 29

2 Answers2

0

Hope this will work for you. It did work for me..

In UIButton's IBAction method check whether your text field is the first responder. If it is the first responder resign it. That will dissmiss the keyboard and perform the buttons action.

-(IBAction)btn:(id)sender
 {
  if ([txt isFirstResponder]) 
   {
    [txt resignFirstResponder];
   }
 UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"hi" message:@"Hello" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
 [alert show];
}

Button action plus resigning first responder

Midas
  • 930
  • 2
  • 8
  • 20
  • This didn't work, since the IBAction that was added to the button wasn't fired at all. It never came into that method.. – Terrabythia Feb 16 '13 at 12:20
  • @SanderBruggeman : Can you add your IBAction code? Because it works fine for me. – Midas Feb 18 '13 at 05:20
0

Changing the button initialization to lazy might fix the problem, as was suggested in this answer.

Shaked Sayag
  • 5,712
  • 2
  • 31
  • 38