UITableViewController和UITextField键盘 [英] UITableViewController and UITextField keyboard

查看:316
本文介绍了UITableViewController和UITextField键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有分组静态UITableView的UITableViewController。我在故事板上为我的静态表视图定义单元格。其中一个单元格中有一个文本字段。当调用此文本字段时,键盘会弹出,但是,表视图不会像通常在表视图控制器上那样自动调整大小。所以现在键盘部分覆盖了文本区域,我无法向上滚动。

I have a UITableViewController with a grouped static UITableView. I am defining the cells for my static table view on the storyboard. One of the cells has a textfield in it. When this textfield is called, the keyboard pops up, however, the tableview is not automatically resizing like it normally would on a table view controller. So now the keyboard is partially covering the textfield and I can't scroll up.

我的理解是当你使用UITableViewController和tableview时,可调区域应该在调用键盘时自动缩小。它确实在我的应用程序的其他部分中工作,而不是使用此静态表视图。它不适用于静态表吗?还有其他我想念的东西吗?有没有一种简单的方法可以解决这个问题?

My understanding is that when you are using a UITableViewController and a tableview, the viewable area should automatically shrink when the keyboard is called. It does work as intended in other parts of my app, just not with this static table view. Does it not work with static tables? Is there something else I am missing? Is there an easy way to solve this?

谢谢

推荐答案

回答

它与静态单元格无关。他们应该工作。

It has nothing to do with static cells. They should work.

如果您的控制器已经是UITableViewController,请检查您是否使用了 viewWillAppear 方法。如果你这样做,你必须调用 [super viewWillAppear:YES] 来使自动行为起作用。

If your controller is already a UITableViewController, check if you used the method viewWillAppear. If you did, you have to call [super viewWillAppear:YES] to get the 'automatic behavior' to work.

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES]; // This line is needed for the 'auto slide up'
   // Do other stuff
}

这个问题很容易出现,因为控制器的样板代码没有附带 viewWillAppear 方法调用,如果你在控制器中定义它,你覆盖它。

This problem turns up easily because the boilerplate code for the controllers don't come with the viewWillAppear method call and if you define it in your controller, you override it.

额外信息

请看这个链接。

Apple Table View编程指南


注意:UITableViewController在iOS 3.0中具有新功能。
表视图控制器支持对表视图行进行内联编辑;如果,
例如,行在编辑模式下嵌入了文本字段,那么
会在虚拟键盘上方滚动正在编辑的行,即
显示.... blah ....

Note: UITableViewController has new capabilities in iOS 3.0. A table-view controller supports inline editing of table-view rows; if, for example, rows have embedded text fields in editing mode, it scrolls the row being edited above the virtual keyboard that is displayed.... blah....

重要位


UITableViewController类通过
重写loadView,viewWillAppear:以及从
UIViewController继承的其他方法来实现上述行为。在UITableViewController的子类中,您可以使用
覆盖这些方法来获取特殊行为。如果你执行
覆盖这些方法,请确保调用该方法的超类
实现,通常作为第一个方法调用,以获得
的默认行为。

The UITableViewController class implements the foregoing behavior by overriding loadView, viewWillAppear:, and other methods inherited from UIViewController. In your subclass of UITableViewController, you may also override these methods to acquire specialized behavior. If you do override these methods, be sure to invoke the superclass implementation of the method, usually as the first method call, to get the default behavior.

这篇关于UITableViewController和UITextField键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆