4

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?

  • What if you are nesting your `UITableViewController` into `UISplitViewController` as `detailViewController`. It will stops auto scrolling. Reason is not cleared yet, seems to bug. – jeeeyul Jan 09 '15 at 04:32

3 Answers3

14

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.

ader
  • 5,403
  • 1
  • 21
  • 26
  • 11
    Thank you ade! We ran into the same thing; it worked, then it didn't work and couldn't see why. To elaborate on your answer, you can still override the viewWillAppear: method and keep the automagic scrolling by calling [super viewWillAppear:animated] inside your own viewWillAppear: method. – joelsand Sep 28 '12 at 02:54
  • ah, it's likely that that was what I was missing, cheers for the clarification :) – ader Sep 28 '12 at 08:07
  • 1
    Thank you so much! I was going crazy here! As we all should know, adding [super viewWillAppear:animated]; will make it work as supposed to again (as joelsand also said). – Olof_t Oct 02 '12 at 15:34
  • 2
    From the documentation: "This method is called before the receiver’s view is about to be added to a view hierarchy and before any animations are configured for showing the view. You can override this method to perform custom tasks associated with displaying the view. For example, you might use this method to change the orientation or style of the status bar to coordinate with the orientation or style of the view being presented. **If you override this method, you must call super at some point in your implementation.**" – Ethan Mick May 08 '13 at 15:07
  • i am using `UITableViewController` if i don't use `supper.viewWillApper()` function then my footer is not coming on the top of `keyBoard` what should i do for that `Means i want to stop auto scrolling and want footer view on the top of keyboard while editing` – Pushpendra Apr 05 '17 at 10:00
4

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.

mbh
  • 3,302
  • 2
  • 22
  • 24
  • 1
    Hey. Du you know what specifically needs to be compliant to make this work? Recently we have exchanged out standard UITabbarController with a custom written menu. Now: If i set focus to a inputfield inside a custom cell, the uitableview is not properly resized to fit above the keyboard and the inputfiled is stuck below the keyboard. – esbenr Aug 21 '12 at 14:43
  • @esbenr See ade's answer - are you overriding the viewWillAppear method in your UITableViewController? – joelsand Sep 28 '12 at 02:56
  • 2
    Just to close this thread. I've figured out what the problem is. If your ViewController derives from UITableViewController (as Apple states it should be) then the UITableViewController clas handles this behaviour for you by implementing UITextFieldDelegate, UIScrollViewDelegate etc. My application stopped doing this as i changed to derive from UIViewController and add the tableview on top of the viewcontrollers uiview. So basically I'm missing the features from UITableViewController because I (for other reasons) choose to derive from UIViewControler. – esbenr Nov 17 '12 at 13:35
  • Cudos to esbenr--and when the app crashes in iOS 6, see http://stackoverflow.com/questions/11221802/nib-but-didnt-get-a-uitableview. – Mike May 03 '13 at 15:00
-5

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.

Shubhank
  • 21,721
  • 8
  • 65
  • 83