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?
Keyboard notifications work, but Apple's sample code for that assumes that the scroll view is the root view of the window. This is usually not the case. You have to compensate for tab bars, etc., to get the right offset.
It is easier than it sounds. Here is the code I use in a UITableViewController. It has two instance variables, hiddenRect and keyboardShown.
Very interesting discussion thread, i also faced the same problem may be worse one because
So read the threads here and implemented my version, which helped me in pushing up my contents in iPad in landscape mode. Here is code ( this is not fool proof and all, but it fixed my issue) First u need to have a delegate in your custom cell class, which on editing begins, sends the textfield to ur viewcontroller and set the activefield = theTextField there
// IMPLEMENTED TO HANDLE LANDSCAPE MODE ONLY
// Called when the UIKeyboardWillHideNotification is sent
-anoop4real
An example in Swift, using the exact point of the text field from Get indexPath of UITextField in UITableViewCell with Swift:
I had the same problem but noticed that it appears only in one view. So I began to look for the differences in the controllers.
I found out that the scrolling behavior is set in
- (void)viewWillAppear:(BOOL)animated
of the super instance.So be sure to implement like this:
And it doesn't matter if you use
UIViewController
orUITableViewController
; checked it by putting aUITableView
as a subview of self.view in theUIViewController
. It was the same behavior. The view didn't allow to scroll if the call[super viewWillAppear:animated];
was missing.Another easy method (only works with one section)
Use
UITextField's
delegate
method :Swift
Objective-C