Disabling automatic scrolling of UITableView when editing UITextField inside UITableViewCell(在 UITableViewCell 内编辑 UITextField 时禁用 UITableView 的自动滚动)
问题描述
我在 UITableView
中使用自定义 UITableViewCell
.这些 UITableViewCell
中的每一个都非常高,并且在顶部包含一个 UITextField
.
I'm using custom UITableViewCell
s inside my UITableView
. Each of these UITableViewCell
s 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:
- 使用
UITableViewController
代替UIViewController
- 自行设置数据源和委托. - 重写
viewWillAppear
方法,不调用[super viewWillAppear: animated]
- Use instead of the
UITableViewController
simply aUIViewController
- set the datasource and delegate on your own. - Override the
viewWillAppear
method and don't call[super viewWillAppear: animated]
使用这两种解决方案,您不仅禁用了自动滚动,还禁用了其他一些不错但不是必不可少的功能,这些功能在 Apple 的类参考概述中进行了描述:
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 的自动滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 UITableViewCell 内编辑 UITextField 时禁用 UITableVi


- android 4中的android RadioButton问题 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01