views:

444

answers:

3

Hi All, I know that this is a common problem and the UITableViewController fixed this is iPhone SDK 3.0, but the UITableViewController is not working as I expect, probably due to how I am using it. Here's my problem:

I'm working on a form, which is in a grouped table, which contains some text fields. Those on the lower part of the form get obscured by the keyboard. I know this is an age-old problem, and there are some examples of code to auto scroll, but I've a little bit more to add, and was wondering if anyone has found this, and fixed it.

Firstly: Since 3.0, if your table is controlled by a UITableViewController, you get this scrolling automagically. I've tried it and indeed it does work. However, I want to use a custom background image, which UITableViewController doesn't play ball with. Here's what I've done:

  1. Create the XIB with a plain view, onto which there's an image.
  2. Also inside the XIB, I've a UIViewController (in fact a my-own subclass as I write the data source methods, etc.), which has the table.
  3. In my main view viewDidLoadMethod I've tried this: tableViewController.view.backgroundColor = [UIColor clearColor]; [self.view addSubview:tableViewController.view];

And indeed, the table shows up as I expect it to look. However, when I tap on a text field in the table, I'm not getting the "magic" scrolling that the tableViewController is meant to give me for free.

As it stands, it is the exact same behaviour as I didn't use a TableViewController at all, and dropped the table directly onto the imageView. (Which, frankly, makes for 1 less class, and easier to read code).

The only reason I introduced a TableViewController was to get this auto-scrolling.

Is there something I am missing?

A: 

If you select the last item in table, it really cannot scroll above keyboard, because there's not enough table to scroll. It does scroll as far as it can, but that might not be enough to bring the selected item visible.

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

JOM
Hi JOM,Thanks. I did the same in the end. Really, I was looking for a way to ensure that the UITableViewController looked after it, so I didn't have to. I didn't find a way, so used the many examples out there that does the scrolling.
dermdaly
A: 

Hello,

Have you fix this problem?

Pierre

Pierre
+1  A: 

Resize it; if you want it smooth then use 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];
iwat