0

I have add a view with button in UITableView Header . I have set the height properly, and the button is actually functional when keyboard is not shown. When some textfield was pressed (UITextField in Cell) keyboard will shown, and I have set the table view frame to smaller, so the cell can be clicked, but the problem is the button — when the button is intersect some of it in tableview (when button is not fully shown), the button is not functional and it is functional when the button is fully shown.

I have tried it by placing the button in scroll view instead of placing in the footer or tableview header, it works perfectly. Is this some kind of UITableView header bug? Can it be fixed?

1 Answer 1

0

Add following in your code :

-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{

      if(textField.tag != [[[yourTable indexPathsForVisibleRows] objectAtIndex:0]row])
          [self animateTextField: textField up: NO];
    return YES;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{

    if(textField.tag != [[[yourTable indexPathsForVisibleRows] objectAtIndex:0]row])
    [self animateTextField: textField up: YES];
}

- (void) animateTextField: (UITextField*) textField up: (BOOL) up
{
    const int movementDistance = 300; // tweak as needed
    const float movementDuration = 0.3f; // tweak as needed

    int movement = (up ? -movementDistance : movementDistance);

    [UIView beginAnimations: @"anim" context: nil];
    [UIView setAnimationBeginsFromCurrentState: YES];
    [UIView setAnimationDuration: movementDuration];
    self.view.frame = CGRectOffset(self.view.frame, 0, movement);
    [UIView commitAnimations];
}
2
  • what is this code for? and where should I put it? Can you explain why this is happening?
    – Lunayo
    Oct 10, 2011 at 11:20
  • This code is for adjusting the view frame when keyboard is textfield is pressed and keyboard appears. Place it in the viewController where you are having the trouble.
    – Nitish
    Oct 10, 2011 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.