views:

19

answers:

0
  • For most of my table view cells, I select a cell and a UIPickerView, added to the view of a UINavigationController, slide up from some offscreen position. I hit the done button in the navigation bar and the whole thing goes away nicely. I also automatically scroll the table view so the selected cell ends up right above the picker view using an animated change of inset followed by a scrollToRowAtIdex.

  • The problem occurs when I then select a cell containing a UITextField that I want to add numbers to. While the navigation controller is still up covering half the screen with the picker view, I want the picker view to slide down and the number pad to slide up.

It works but the entire tableview also jumps up above the screen and I have to scroll it back down to see it.

My only guess as to what's going on is that when I create a contentOffset to be able to scroll my tableView further up using:

self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 250, 0);

followed by a:

[self.tableView scrollToRowAtIndexPath:textFieldIndexPath atScrollPosition:
UITableViewScrollPositionMiddle animated:YES];

this somehow interferes or obscures the natural behavior of a UITextField. I've tried adjusting the offset and removing the offset before I call:

textField.enable = YES;
[textField becomeFirstResponder];

but this has only caused the tableView to do a sort of wiggle as it scrolls down and then up again.

Has anyone solved this problem? Does anyone know more about what is actually going on so I can deal with it better?

This is the animation I use to slide down the picker view while the number pad slides up:

[UIView beginAnimations:nil context:NULL]; // picker go down
        [UIView setAnimationDuration:0.3]; 
        pickerViewController.view.transform = CGAffineTransformMakeTranslation(0, 400);
        [UIView setAnimationDidStopSelector:@selector(textScroll)];
        [UIView commitAnimations];
[textView beginEditing];

The @selector(textScroll) is the method that contains the scroll command I included above. The beginEditing just enables the textField and makes it the first responder and YES, I did try calling begin editing before this animation block. It had the same result.