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.
-(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.
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];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With