IQKeyboardManager does not work when UITableView is embedded in the container view

I am currently working with a container view with a built-in UITableView and use IQKeyboardManager IQKeyboardManager to scroll the view, so my UITextFields and UITextViews not covered by the keyboard.

I can successfully import IQkeyboardManager and make it work in other views, but it does not work when the UITableView is embedded in the container view.

+7
ios uitableview swift uicontainerview iqkeyboardmanager
source share
3 answers
  -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:YES]; // This line is needed for the 'auto slide up' // Do other stuff } 

A simple solution, no need to create an observer.

+4
source share

I had a similar problem, and I fixed it using the information provided here from the author of the library.

Key statement:

library logic - find the nearest scrollView from textField. and in your case it is a tableView, so the library selects a tableView to scroll through.

So the solution I used was to disable the scroll property of the UITableView when editing a text field / view (use delegate methods), and then turn it back on after editing was completed. This ensures that the library does not detect the UITableView as scrollable, and therefore it ignores it, and then instead moves your container view - as you expected. After the view has moved up as you wish, you can re-enable scrolling through UIKeyboardWillShowNotification.

So, for example, for a UITextField:

 -(void) textFieldDidBeginEditing:(UITextField *)textField { [self.tableView setScrollEnabled:NO]; } - (void) textFieldDidEndEditing:(UITextField *)textField { [self.tableView setScrollEnabled:YES]; } 

However, in order to allow scrolling after the view has moved up, I registered to notify the keyboard, and then allowed scrolling after the keyboard is up:

 -(void) keyboardWillShow { [self.tableView setScrollEnabled:YES]; } - (void)viewDidLoad { [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil]; } 
+3
source share

try to scroll through all your views

in viewDidLoad

 NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(YourVC.keyboardWillShow(_:)), name:UIKeyboardWillShowNotification, object: nil) NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(YourVC.keyboardWillHide(_:)), name:UIKeyboardWillHideNotification, object: nil) 

and after

 func keyboardWillShow(notification:NSNotification) { if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() { self.view.frame.origin.y -= keyboardSize.height } } func keyboardWillHide(notification:NSNotification) { if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() { self.view.frame.origin.y += keyboardSize.height } } 

you can change keyboardSize

-one
source share

All Articles