简体   繁体   English

iOS 5问题:拉起UITextView时键盘消失

[英]iOS 5 issues: Disappearing keyboard when pulling up a UITextView

I have a nice little app on the app store that does pretty well for itself. 我在App Store上有一个不错的小应用程序,它本身表现很好。 Life was great until iOS 5 came to town. 在iOS 5出现之前,生活一直很美好。 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. 现在,我的应用存在很多问题,我无法解决,因为我不知道发生了什么,因为我认为这是iOS 5问题,而不是我的问题。

Was there an iOS 5 conversion manual I missed? 我错过了iOS 5转换手册吗? 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: 这是我遇到的一个问题(我浪费了太多时间进行修复),当我只是简单地说我想在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. 因此,当我拉起一个简单的模式视图时,选择一个tableView单元格,然后显示一个textView,以便用户可以输入一些文本。 When the textView becomes visible, I call [textView becomesFirstResponder]; 当textView变为可见时,我调用[textView变成FirstResponder]; 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! 然后,当您关闭modalView(并得到我上面刚刚提到的怪异错误),然后尝试返回modalView并拉起textView时,键盘飞走了! You see it for a fraction of a second, and then POOF it's gone. 您会看到一秒钟的时间,然后POOF消失了。 I have a textView upon which my cursor is active and I am trying to edit, but my keyboard refuses to show up. 我有一个textView,光标处于活动状态,正在尝试编辑,但是键盘拒绝显示。 Again, this works perfectly in 4.2, but not in 5! 同样,这在4.2中完美运行,但在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]; 第二个单元格应该是可编辑的,因此,当用户点击该单元格时,我将取消隐藏隐藏在viewDidLoad上的UITextView,然后调用[textView成为FirstResponder]。 on the textView, and it works fine. 在textView上,并且工作正常。 The textView is editable, and it hides and updates the appropriate cell content when the keyboard is dismissed. textView是可编辑的,并且在关闭键盘时可以隐藏和更新适当的单元格内容。

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. 问题是,当我关闭模态视图,然后回到模态视图,并选择可编辑单元格时,textView会显示得很好,并且是可编辑的,但是键盘会闪烁到屏幕上,然后飞走并赢得不显示。 So I have my textView there and editable, but try as I might, the keyboard won't show! 因此,我在那里有textView并且可以编辑,但是我尝试尝试一下,键盘不会显示! It's absolutely driving me nuts, especially because it works perfectly on iOS 4.2. 这绝对让我发疯,尤其是因为它在iOS 4.2上完美运行。

I have the feeling it has something to do with the way you present and dismissing the modalview. 我觉得它与您介绍和消除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: 引入iOS 5引入的新首选方法:

presentViewController:animated:completion:

Depending if you are using dismissModalViewControllerAnimated: to dismiss your view, change it into dismissViewControllerAnimated:completion . 根据您是否正在使用dismissModalViewControllerAnimated:来关闭视图,将其更改为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. 让我知道是否有帮助。

i just found out on Apple's developers website this page . 我刚刚在Apple开发人员网站上找到此页面 I don't know exactly if it's the right thing but there are some documents called "iOS 4.x API diffs". 我不知道这是否正确,但是有些文档称为“ iOS 4.x API diffs”。 Seems to be a list of differences from 4.x to 5.x. 似乎是从4.x到5.x的差异列表。 Hope this can help. 希望这会有所帮助。 Bye 再见

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. 我应该将shouldAutorotateToInterfaceOrientation值设置为可以从TURE或FALSE更改的BOOL变量,以便在modalView返回时,有可能它不知道状态栏的状态/大小。 By manually setting it to TRUE, it fixed the issue, and the problem disappeared. 通过手动将其设置为TRUE,它解决了问题,问题消失了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM