user843337
user843337

Reputation:

Why won't UITableView 'Auto-scroll' when editing UITextField (in UITableViewCell)? (iPhone)

I have created a UITableView that is of type UITableViewStyleGrouped. I have then created several different sections with a few rows in each. Within each of these rows I have created a custom UITableViewCell that contains a UITextField. I also have one UITableViewCell that contains a UITextView.

I have also implemented a UIToolbar that appears on top of the UIKeyboard that allows the user to move through the UITextField's by pressing previous or next.

The issue I'm having is two-fold:

  1. I need the UITableView to scroll so that when the next UITextField (or UITextView) becomes the first responder it is visible (even with the keyboard being displayed).
  2. When a UITextField (or UITextView) is selected (without using the previous and next buttons) is should adjust so that the field is visible above the keyboard.

I have looked around at lots of different tutorials however none of them have resolved my issue. Any help you could offer would be hugely appreciated.

ADDITIONAL INFO:

I'm 100% certain that my app used to do all of the above automatically, however I seems to have stopped doing it now and I don't understand why. Is there a reason why this may of happened? Is there some function or something that I may have changed that would destroy this behaviour?

Upvotes: 4

Views: 5112

Answers (3)

ader
ader

Reputation: 5393

Probably no use to original poster now, but those having an issue like this where it once did work and then stopped...

check you don't have a:

- (void)viewWillAppear:(BOOL)animated

in your UITableViewController subclass!!!

using viewWillAppear in a UITableViewController breaks the "automagic tableView scrolling up when keyboard appears" behaviour.

I only found this by comparing laboriously an old version of a project where it did work with my latest source where it had stopped working.

Upvotes: 14

mbh
mbh

Reputation: 3312

Check out TaggedLocations sample code from apple. It does the same thing without any extra manipulation.

The key is that your viewcontrollers are following the standard. i.e you are NOT having container viewcontrollers such as UINavigationController within UIViewController.

Upvotes: 4

Shubhank
Shubhank

Reputation: 21805

You have to update tableview Frame yourself programatically... and i am 100% sure that if you are 100% certain that your app used to do all of the above automatically ...than it is not your app.

Check the docs..here is the link

https://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/ManageTextFieldTextViews/ManageTextFieldTextViews.html#//apple_ref/doc/uid/TP40009542-CH10-SW1

You will have to register for keyboard notifications..and then update your tableview frame. And for next and previous.. you have to programmatically check which textfield became active..and then set the frame accordingly.

Upvotes: -5

Related Questions