简体   繁体   English

出现键盘时,带有大单元格的UITableViewController会变怪,隐藏UITextView

[英]UITableViewController with large cells freaks out when a keyboard appears, hiding the UITextView

I created a new project just to test this. 我创建了一个新项目来进行测试。

Demo 演示版

Create a Master-Detail project. 创建一个主从项目。 On the Main_iPhone.storyboard : Main_iPhone.storyboard

  1. Change the prototype cell style to Custom. 将原型单元格样式更改为“自定义”。
  2. Make the Table View's row height 504 to fill the whole screen with each cell. 使表格视图的行高504充满每个单元格的整个屏幕。
  3. Put a UITextView filling the bottom half of the prototype cell. 将一个UITextView填充到原型单元的下半部分。
  4. In MasterViewController.m , Remove this line from cellForRowAtIndexPath: MasterViewController.m ,从cellForRowAtIndexPath:删除以下行cellForRowAtIndexPath:
cell.textLabel.text = [object description];

Run the project and add some cells. 运行该项目并添加一些单元格。 Then tap on the text view to edit the content. 然后点击文本视图以编辑内容。

Description of the problem 问题描述

Every time I tap on the Text View, the cell scrolls up to reveal the text view momentarily (as it should), and then scrolls back down so that the top of the cell is visible, which hides the text view behind the keyboard. 每次我单击“文本视图”时,单元格都会向上滚动以暂时显示该文本视图(应如此),然后向下滚动以使该单元格的顶部可见,从而将文本视图隐藏在键盘后面。

Video 视频

This question has a video of the problem: UITableView in iOS 7 not scrolling to correct location when editing UITextView in cell 这个问题有一个视频的问题: 在单元格中编辑UITextView时,iOS 7中的UITableView无法滚动到正确的位置

Question

What could be causing this? 是什么原因造成的? Can you find any Apple documentation that talks about how a UITableViewController handles keyboards? 您能找到任何有关UITableViewController如何处理键盘的Apple文档吗?

I was able to hack around this problem using TPKeyboardAvoidingTableView and adding this to my UITableViewController subclass: 我能够使用TPKeyboardAvoidingTableView解决这个问题,并将其添加到我的UITableViewController子类中:

- (void)viewWillAppear:(BOOL)animated
{
    // Removed to avoid default tableview scrolling behavior when the keyboard appears
    //[super viewWillAppear:animated]; 
}

Just using TPKeyboardAvoidingTableView alone was not enough, because the default behavior from the UITableViewController would override it. 仅使用TPKeyboardAvoidingTableView是不够的,因为UITableViewController的默认行为会覆盖它。 Preventing viewWillAppear from running was the only way I could find to stop that behavior. 阻止viewWillAppear运行是我发现停止该行为的唯一方法。 But I dislike this solution because I don't know what else I might be loosing. 但是我不喜欢这种解决方案,因为我不知道我还会失去什么。

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

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