I have a view which has tableview on top and a search textfield (with a button) at bottom of tableview. I am trying to implement the dynamic search so that as and when user types the tableview is reloaded. The searchfield comes nicely on top of keyboard and does the search. But in some cases it goes below the keyboard while user is still typing. This typically happens when search returns 0 results which means tableview is empty or if tableview has rows which just fit the height allocated to tableview. I am not sure why does the tableview reload makes the search field go back to the bottom of the page even though the search field is not part of tableview.
Here is the code I use to move the search field based on keyboard state :
- (void)adjustView:(NSNotification *)notification {
CGRect keyboardFrame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
keyboardFrame = [self.view convertRect:keyboardFrame fromView:self.view.window];
CGRect viewFrame = self.searchView.frame;
viewFrame.origin.y = keyboardFrame.origin.y - viewFrame.size.height;
self.searchView.frame = viewFrame;
}
Here searchView is the view containing the textfield and a button. Any help is greatly appreciated.