iOS 5 issues: Disappearing keyboard when pulling up a UITextView

别来无恙 提交于 2019-12-24 09:00:08

问题


I have a nice little app on the app store that does pretty well for itself. Life was great until iOS 5 came to town. Now, I have a number of issues with my app that I have no way of fixing because I have no clue what is going on, because I feel that they are iOS 5 issues, not mine.

Was there an iOS 5 conversion manual I missed? Or did they just change everything for fun, and want us to figure out where all the easter eggs were?

Here is an issue I am experiencing (that I have wasted so much time trying to fix), that DON'T EXIST AT ALL when I simply say that I want to run the app in good ol' 4.2:

Disappearing keyboard

So when I pull up a simple modal view, I select a tableView cell, and then I present a textView so that users can enter some text. When the textView becomes visible, I call [textView becomesFirstResponder]; so that the keyboard is up and ready for the user to use. This works the first time. Then, when you dismiss the modalView (and get the weird error I just mentioned above), and then try and go back into the modalView, and pull up the textView, the keyboard flies away! You see it for a fraction of a second, and then POOF it's gone. I have a textView upon which my cursor is active and I am trying to edit, but my keyboard refuses to show up. Again, this works perfectly in 4.2, but not in 5!

I have tried everything under the sun to get these issues worked out, but I just can't get them working. What should I do? I feel that these are bugs on the OS side, not mine!

Thanks for your help.

Edit:

To be more clear, I will go over what I am trying to accomplish with my view hierarchy. When I display my modal view, I have two different cells that I fill up with some text. The second cell is supposed to be editable, so when the user taps the cell, I unhide a UITextView that I hid on viewDidLoad, and call [textView becomeFirstResponder]; on the textView, and it works fine. The textView is editable, and it hides and updates the appropriate cell content when the keyboard is dismissed.

The problem is that when I dismiss the modal view, then came back into the modal view, and select the editable cell, the textView shows up just fine, and it is editable, but the keyboard blips onto the screen but then flys away and won't show. So I have my textView there and editable, but try as I might, the keyboard won't show! It's absolutely driving me nuts, especially because it works perfectly on iOS 4.2.


回答1:


I have the feeling it has something to do with the way you present and dismissing the modalview. Apple introduced a new method to present views. May you try using theses instead of the old ones and see if it fixes your problem.

So here is what you do:

change this method:

presentModalViewController:animated:

into the new preferred method introduced with iOS 5:

presentViewController:animated:completion:

Depending if you are using dismissModalViewControllerAnimated:to dismiss your view, change it into dismissViewControllerAnimated:completion.

This methods also have completion handler which is very useful to do some extra work after the view has been presented/dismissed. Maybe that also helps with your other issue. Let me know if that might helped.




回答2:


i just found out on Apple's developers website this page. I don't know exactly if it's the right thing but there are some documents called "iOS 4.x API diffs". Seems to be a list of differences from 4.x to 5.x. Hope this can help. Bye




回答3:


Ok, I was just able to figure out what in the blazes was going on. I had the shouldAutorotateToInterfaceOrientation value set to a BOOL variable that could change from TURE or FALSE, so that when the modalView was coming back, there was a chance that it didn't know the state/size of the status bar. By manually setting it to TRUE, it fixed the issue, and the problem disappeared.



来源:https://stackoverflow.com/questions/8259601/ios-5-issues-disappearing-keyboard-when-pulling-up-a-uitextview

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