在UITableViewCell中编辑UITextField时禁用UITableView的自动滚动 [英] Disabling automatic scrolling of UITableView when editing UITextField inside UITableViewCell

查看:106
本文介绍了在UITableViewCell中编辑UITextField时禁用UITableView的自动滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UITableView 中使用自定义 UITableViewCell 。这些 UITableViewCell 中的每一个都非常高,顶部包含 UITextField

I'm using custom UITableViewCells inside my UITableView. Each of these UITableViewCells is pretty high and contains a UITextField at the top.

当用户点击 UITextField 进行编辑时,会出现一个键盘, UITableView 自动滚动,以便单元格位于屏幕顶部。

When a user taps the UITextField in order to edit it, a keyboard appears and the UITableView scrolls automatically so that the cell is at the top of the screen.

问题是这会将 UITableView 滚动到 UITableViewCell的底部,而不是顶部。当 UITableViewCell 为高并编辑时, UITextField 位于顶部,因此您无法看到的UITextField 。我知道如何以编程方式滚动 UITableView ,但我只是不知道如何禁用这种自动滚动,以便我可以滚动 UITableView 我自己。我怎样才能做到这一点?

The problem is that this scrolls the UITableView to the bottom of the UITableViewCell, not the top. When the UITableViewCell is high and edited the UITextField is at the top so you can't see the UITextField. I know how to scroll the UITableView programmatically, but I just don't know how to disable this automatic scrolling so that I can scroll the UITableView on my own. How can I do this?

推荐答案

在自动滚屏行为位于的UITableViewController 功能。

The autoscroll-behavior is located in the UITableViewController functionality.

要禁用自动滚动,我发现了两种方法:

To disable the automatic scrolling I found two ways:


  1. 使用而不是 UITableViewController 只需 UIViewController - 自行设置数据源和委托。

  2. 覆盖 viewWillAppear 方法,不要调用 [super viewWillAppear:animated]

  1. Use instead of the UITableViewController simply a UIViewController - set the datasource and delegate on your own.
  2. Override the viewWillAppear method and don't call [super viewWillAppear: animated]

使用这两种解决方案,您不仅可以禁用Autoscroll,还可以禁用其他一些不错但不是必需的功能,这些功能在Apple的概述中有所描述。 s类参考:

With both solution you disable not only the Autoscroll, but also some other nice but not essential features, that are described in the overview of Apple´s class reference:

https:// developer.apple.com/documentation/uikit/uitableviewcontroller

这篇关于在UITableViewCell中编辑UITextField时禁用UITableView的自动滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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