Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had the same issue. I found that I need to prevent call <code>[UIView viewWillDisappear:]</code> before the keyboard hides.</p> <p>My solutions for this.</p> <pre><code>// useful method, thus I don't need to remember current first responder @interface UIView (FindAndResignFirstResponder) - (BOOL)findAndResignFirstResonder; @end // --- @implementation UIView (FindAndResignFirstResponder) // http://stackoverflow.com/questions/1823317/how-do-i-legally-get-the-current-first-responder-on-the-screen-on-an-iphone - (BOOL)findAndResignFirstResonder { if (self.isFirstResponder) { return [self resignFirstResponder]; } for (UIView *subView in self.subviews) { if ([subView findAndResignFirstResonder]) { return YES; } } return NO; } @end // --- @interface MyTableViewController : UITableViewController { // some booleans required to track state of keyboard and view BOOL hidingKeyboard; BOOL viewWillDisappear; BOOL viewWillDisappearAnimated; } // methods for keyboard event handling - (void)keyboardWillHide:(id)sender; - (void)keyboardDidHide:(id)sender; @end // --- @implementation MyTableViewController - (void)viewDidLoad { [super viewDidLoad]; // adding observer for keyboard events (notifications) [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil]; hidingKeyboard = NO; viewWillDisappear = NO; } - (void)viewDidUnload { [super viewDidUnload]; // removing observer [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)viewWillDisappear:(BOOL)animated { // finding and resigning first responder [self.view findAndResignFirstResonder]; if (hidingKeyboard) { // if keyboard hide animation in process, // remembering to run [super viewWillDisappear:] after keyboard hides viewWillDisappear = YES; viewWillDisappearAnimated = animated; } else { // if there is no keyboard hide animation, // calling super immediately [super viewWillDisappear:animated]; } } - (void)keyboardWillHide:(id)sender { hidingKeyboard = YES; } - (void)keyboardDidHide:(id)sender { hidingKeyboard = NO; if (viewWillDisappear) { // calling [super viewWillAppear:] after keyboard hides, if required viewWillDisappear = NO; [super viewWillAppear:viewWillDisappearAnimated]; } } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload