Keyboard loses hiding ability “if I use a UIAlertView”

流过昼夜 提交于 2019-12-03 08:27:00
Isaac

I've finally solved my problem. I'm more than sure that I could have done better, but for now, even I still don't know "what causes the aforementioned behaviour", I'm more than happy.

The thing is that if I "popped back" a view, FROM inside the UIAlertView delegate code, iOS thinks it's something I shouldn't do, and its internal keyboard management code "becomes out of control". It's as if I'm popping back "too soon", or without having let iOS close whatever keyboard data structures it needed to close.

So a coworker (aleixventa) gave me a hint: "Why don't you delay a bit the 'popback' code, wrapping it inside a "NSTimer structure"?. And that's precisely what I did. My 'pop back' manual code, is now this:

NSTimer* testTimer = [NSTimer scheduledTimerWithTimeInterval:.05 target:self selector:@selector(popViewPorTimer) userInfo:nil repeats: NO];

Having a small function for my popViewPorTimer selector:

-(void) popViewPorTimer
{
    [[self navigationController] popViewControllerAnimated:YES];
}

And now, no matter how many times the keyboard is dismissed via "Navigation pop back", it always becomes hidden. YAY!!

For extra bonus, if someone knows why all this happens, it will be a more than welcome piece of info.

I love when I "solve my questions" by myself :)

Isaac

Well, I must have been completely misled, because I've removed all traces of [self.view endEditing:YES] and/or resignFirstResponder in ALL my .m files and I've discovered 2 things:

1.- They weren't doing ANYTHING. Keyboard auto disappears when needed.

2.- The bug I originally described, is still there.

So, as far as I know, when I just "press back" in the actual UINavigationBar "Back" button (in any inner view), the view, pops back, and if keyboard was present, it disappears. So far so good.

Then some other times, I need to simulate a "Back" press button. I do it with:

[[self navigationController] popViewControllerAnimated:YES];

It works flawlessly, that is, it just pops back, and if keyboard was present, it disappears.

BUUUT, if I write this "manual back" action INSIDE some UIAlertView Delegate I also need (where I deal with two Accept/Cancel buttons), this "manual back action" also pops back to the "parent" view (always, that's OK), but it hides the keyboard ONLY the first time it's called. Succesive calls to "manual back" via this accept/cancel UIAlertDelegate function, render the "keyboard hiding engine" completely unusable for the rest of the session.

I'm plain lost.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!