問題描述
我在 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 的自動滾動的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!