开发者

iPad popover textfield - resignFirstResponder doesn't dismiss keyboard

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 does not work (becomeFirstResponder works). textFieldsShouldReturn was called for both fields. Any idea if I am missing something? Thanks!

  - (BOOL)textFieldShouldReturn:(UITextField *)theTextField {

     if (theTextField == email) {
         [password becomeFirstResponder];
         return NO;
     }

     [theTextField resignFirstResponder];
     return NO;
}


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;
}


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


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.


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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜