After a lot of trial and error, I'm giving up and asking the question. I've seen a lot of people with similar problems but can't get all the answers to work right.
I have a UITableView
which is composed of custom cells. The cells are made of 5 text fields next to each other (sort of like a grid).
When I try to scroll and edit the cells at the bottom of the UITableView
, I can't manage to get my cells properly positioned above the keyboard.
I have seen many answers talking about changing view sizes,etc... but none of them has worked nicely so far.
Could anybody clarify the "right" way to do this with a concrete code example?
THE RIGHT ANSWER is Sam Ho's answer:
"If you use UITableViewController instead of UIViewController, it will automatically do so.".
Just make sure to connect your UITableView to the TableView property of the UITableViewController (so e.g. do not add it as a subview of the View property of the UITableViewController).
Also make sure to set the AutoresizingMask property of your UITableView to FlexibleHeight
I tried almost the same approach and came up with a simpler and smaller code for the same. I created a IBOutlet iTextView and associated with the UITextView in the IB.
If you use UITableViewController instead of UIViewController, it will automatically do so.
I ran into something like your problem (I wanted a screen similar to the iPhone's settings.app with a bunch of editable cells stacked on on top of another) and found that this approach worked well:
sliding uitextfields around to avoid
The simplest solution for Swift 3, based on Bartłomiej Semańczyk solution:
If you use
Three20
, then use theautoresizesForKeyboard
property. Just set in the your view controller's-initWithNibName:bundle
methodThis takes care of:
Done and done.