質問

I am working on a project where I have a UITableView containing a large number of cells. One of these cells contain a UITextField. When I tap the UITextField the keyboard appears. The problem is that the text field is now hidden by the keyboard.

I am using story boards and I have set automaticallyAdjustsScrollViewInsets to YES. All views are correctly extended beneath the navigation bar and the tab bar in my application, however I would expect it to also adjust the insets when the keyboard is displayed. Or do I need to adjust this manually?

If I need to adjust this manually, how would I revert the view to the original insets automatically set by the system? Should I make a copy of these insets in awakeFromNib or at which stage can I be sure that the system has adjusted the insets?

役に立ちましたか?

解決 2

I finally found the issue, it was really stupid. I accidentally haves a standard UIViewController handling my UITableView. The UITableView is my main view and it is not contained in a standard UIView.

When I replaced the UIViewController inheritance with just UITableViewController, everything started working as expected.

他のヒント

You want to implement something like this:

-(BOOL)textFieldShouldBeginEditing:(UITextField*)textfield
{
    UITableViewCell *currentCell = (UITableViewCell *) textField.superview.superview;
    NSIndexPath *currentIndexPath = [self.tableView indexPathForCell:currentCell];

    [self.tableView scrollToRowAtIndexPath:nextIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES]; 

    return YES;
}

Assuming you have your UITextField and UITableView delegates set to the controller, this will cause the view to scroll the UITableViewCell to the top of the UITableView.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top