Another question about "keyboard hiding UITextField problem"

I know this is a common problem and the UITableViewController fixed this iPhone SDK 3.0, but the UITableViewController does not work as I expect, possibly due to the way I use it. Here is my problem:

I am working on a form that is in a grouped table that contains some text fields. Those at the bottom of the form are covered by the keyboard. I know this is an old problem, and there are some code examples for auto-scrolling, but I will add a little more, and I was wondering if anyone found this and fixed it.

First: starting with 3.0, if your table is controlled by a UITableViewController, you will automatically scroll through this scroll. I have tried and it really works. However, I want to use a custom background image with which the UITableViewController does not play the ball. Here is what I did:

  • Create an XIB with a simple view that has an image.
  • Also inside XIB, I have a UIViewController (actually my subclass when I write data source methods, etc.) that has a table.
  • In my main view, viewDidLoadMethod I tried this: tableViewController.view.backgroundColor = [UIColor clearColor]; [self.view addSubview: tableViewController.view];

And indeed, the table appears, as I expect it to look. However, when I click on a text field in a table, I don't get the “magic” scroll that tableViewController should use to give me free.

In its current form, this is the same behavior that I did not use the TableViewController at all, and dropped the table directly onto imageView. (Which, frankly, makes for 1 smaller class and easier to read code).

The only reason I introduced the TableViewController is autoscrolling.

Is there something I am missing?

+4
source share
3 answers

Change its size; if you want it to be smooth, use an animation block.

[UIView beginAnimations:@"tableAnim" context:nil]; // 214 = keyboard size, adjust it if you have navigation bar or status bar tableView.frame = CGRectMake(0, 0, 320, 480 - 214); [UIView commitAnimations]; 
+1
source

If you select the last item in the table, it really will not be able to scroll over the keyboard, because the table is not enough to scroll. It scrolls as far as possible, but this may not be enough to display the selected item.

What I did was resize the table to be fully visible above the keyboard. It's not as smooth as it should be, but good enough. Each item can be seen.

0
source

(Repeating my answer from another question fooobar.com/questions/1297944 / ... ):

I personally recommend using Michael Tyson's TPKeyboardAvoiding .

It is very easy to use ... (to quote from Read Me):

To use with the UITableViewController classes, select TPKeyboardAvoidingTableView.m and TPKeyboardAvoidingTableView.h in your project and make your UITableView TPKeyboardAvoidingTableView in xib. If you are not using xib with a controller, I know there is no easy way to make your UITableView a regular class: the path of least Resistance is to create xib for it.

For non-strong> UITableViewControllers, release TPKeyboardAvoidingScrollView.m and TPKeyboardAvoidingScrollView.h the source files in your project, enter the UIScrollView in your xib controller view, set the scroll view class to TPKeyboardAvoidingScrollView and put all your controls in this scroll view. You can also create it programmatically, without using xib - just use TPKeyboardAvoidingScrollView as your top-level view.

0
source

All Articles