iPad popover textfield - resignFirstResponder doesn't dismiss keyboard

前端 未结 5 844
执笔经年
执笔经年 2021-02-13 06:15

I have two text fields email and password. The following code works fine when the fields are presented on a regular view but when they are on a popover, the resignFirstResponder

相关标签:
5条回答
  • 2021-02-13 06:50

    Check this question:

    Overriding disablesAutomaticKeyboardDismissal to return NO as below fixed the same problem of mine. You should put this code to your view controller, from which you initiate the keyboard:

    - (BOOL)disablesAutomaticKeyboardDismissal {
        return NO;
    }
    
    0 讨论(0)
  • 2021-02-13 06:50

    I was also having this problem. But I solved this by making a another control, which is not in the popover as firstResponder and later a resigned it from there. But I don't what is the problem with popover.

    0 讨论(0)
  • 2021-02-13 06:53

    The answer is provided as a possible solution to others with a similar problem, but where the conventional remedies don't work.

    In summary -

    I had a similar problem (under a certain condition) and tried everything - to no avail - Included in my list of possible solutions was [obj's resignFirstResponder], the overriding of 'disablesAutomaticKeyboardDismissal' for my view controller, [self.view endEditing:YES]; and a bunch of other things.

    Went about determining the [id] of the current first responder, only to discover it was nil. Tapping 'Done' on the keyboard or using any of the methods above did nothing - the keyboard remained - even after tapping on another input field.

    The screen was essentially a ViewController with a UITableView with a text input field in each cell - 7 or 8 in total. Tapping on any cell would bring up keyboard as expected and tapping a separate 'Next' button (to hide the keyboard plus other processing) worked as expected. However, in landscape mode, the last field was covered by the keyboard requiring the table to be scrolled to reveal such.

    After scrolling and tapping that last input field, the keyboard could not be dismissed - no matter what. The only work around was to scroll the table back under the keyboard, then tap the 'next' button. It doesn't make sense.

    Almost at the point of giving up (and implementing a workaround), the solution that worked was to make that last input field the firstResponder (even though it already had a blinking cursor) and then to resignFirstResponder after that.

    So;

    `-(void) actionNext {

    [[m_arrInputFields objectAtIndex:7] becomeFirstResponder];
    [[m_arrInputFields objectAtIndex:7] resignFirstResponder];
    

    }`

    fixed the problem - whereas [m_arrInputFields objectAtIndex:#any other index#] did not!

    Would be great if anyone can provide clarity or an explanation for this - else - I hope it saves someone else a few hours of work!

    0 讨论(0)
  • 2021-02-13 07:02

    I'm not too sure about this, but, as I understand the responder hierarchy, resign would work only if you have some other responder to answer.

    In a regular view, the view itself is willing. In a popup, maybe you need to do something to your popup class (like reimplement some Responder methods) in order for this to work.

    0 讨论(0)
  • 2021-02-13 07:12

    As described in this answer, the keyboard will sometimes remain on-screen when the view is presented with the UIModalPresentationFormSheet style.

    0 讨论(0)
提交回复
热议问题