【问题标题】:UITableView in UIViewController auto scroll possible?UIViewController 中的 UITableView 可以自动滚动吗?
【发布时间】:2016-03-24 09:50:04
【问题描述】:

我在UITableView 中有UITextView,我想滚动UITableView 以使UITextView 可见。现在我已经看到了不同的解决方案,包括Apple's。但就我而言,单元格的高度是动态的。 UITextView 可能在单元格中的任何位置。这种方式UITableViewScrollPosition 对我不起作用,因为我已经尝试过使用scrollToRowAtIndexPath
是否有可能的精确解决方案或者就此而言是否可以在键盘出现时自动滚动UITableView(不应该是third party)。

【问题讨论】:

  • 你说的自动滚动是什么意思?
  • @Mr.T : 一旦在点击 UITableView 中的 UITextView 时出现键盘,UITableView 应该根据 UITextView 的位置自动滚动或不自动滚动。

标签: ios iphone uitableview keyboard uitextview


【解决方案1】:

假设您有一个用于粘贴数据的数组,以显示名为tableArray 的数据。在 viewDidLoad 中,您需要像这样在该数组中找到您的 UITextView 对象索引;

let tableArray = ["Data1", "Data2", "Data3", "UITextViewObject", "Data5"]
let indexForSearch: Int?
for k in (0...tableArray.count) {
    if tableArray[k] is UITextView {
        indexForSearch = k
        break
    }
}

然后滚动以编程方式编制索引的表格视图;

yourTableView.scrollToRowAtIndexPath(NSIndexPath(forRow: indexForSearch, inSection: 0), atScrollPosition: .Bottom, animated: true)

【讨论】:

  • 正如我所提到的,我已经尝试过使用 scrollToRowAtIndexPath 但它不起作用,因为 .Bottom 将始终移动到 UITableViewCell 的底部。并且单元格可以在其中的任何位置使用 UITextView 非常高。
猜你喜欢
  • 1970-01-01
  • 2016-08-05
  • 1970-01-01
  • 1970-01-01
  • 2016-02-19
  • 2012-12-27
  • 2016-06-11
  • 2019-09-28
  • 1970-01-01
相关资源
最近更新 更多