I have tableView size set by AutoLayout (bottom to Bottom Layout Guide, top to another view and so on but first UISearchBar to Top Layout Guide):
Controller with tableView:
I need to change table offset when keyboard is shown so I have these two methods:
// MARK: - Keyboard
func keyboardWasShown (notification: NSNotification) {
let info: NSDictionary = notification.userInfo!
let value: NSValue = info.valueForKey(UIKeyboardFrameBeginUserInfoKey) as! NSValue
let keyboardSize: CGSize = value.CGRectValue().size
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, keyboardSize.height, 0)
self.tableView.scrollIndicatorInsets = self.tableView.contentInset
}
func keyboardWillBeHidden (notification: NSNotification) {
self.tableView.contentInset = UIEdgeInsetsZero
self.tableView.scrollIndicatorInsets = UIEdgeInsetsZero
}
And it's working but I have problem when keyboard is shown. The last item can't be selected and instead of that I get previous item. I tapped where is last item and it should navigate to detail page with last item but instead I see detail page with previous item. It isn't shift for all items but just for the last one and when I filtered to just one item it's working okay. When keyboard is hidden (and items are still filtered) then It's okay too (it selects the right thing). So I guess the problem must be here:
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, keyboardSize.height, 0)
self.tableView.scrollIndicatorInsets = self.tableView.contentInset
So where could be problem? Thanks for help