Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IQKeyboardManager not working when UITableView embedded in a container view

Currently, I am working with a container view with an embedded UITableView and am using the IQKeyboardManager CocoaPod to scroll the view so my UITextFields and UITextViews are not covered by the keyboard.

I can successfully import IQkeyboardManager and make it work in other views but it's not working when the UITableView is embedded in a container view.

like image 626
Kushal Maniyar Avatar asked Aug 04 '16 13:08

Kushal Maniyar


2 Answers

    -(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES]; // This line is needed for the 'auto slide up'
   // Do other stuff
}

Simple solution , No need to create observer.

like image 112
vivek agravat Avatar answered Sep 28 '22 04:09

vivek agravat


I've had a similar issue and fixed it using the info given here from the author of the library.

The key statement is:

library logic is to find nearest scrollView from textField. and in your case it's tableView, that is why library chooses tableView to scroll.

So the solution I've used is to disable the UITableView scroll property when the textfield/view is being edited (use the delegate methods), and then re-enable it once editing has finished. This ensures that the library does not detect the UITableView as scrollable and so it ignores it and then moves your container view instead - as you intended. Once the view has moved up as you wanted it to, you can re-enable scrolling via the UIKeyboardWillShowNotification.

So for example, for the UITextField:

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

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

However to still allow scrolling after the view has moved up, I have registered for the keyboard notification and then allowed scrolling once 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];

}
like image 41
SMSidat Avatar answered Sep 28 '22 04:09

SMSidat