gpt4 book ai didi

ios - 当所述行靠近表格 View 的底部时,ScrollToRow 不起作用

转载 作者:行者123 更新时间:2023-12-01 16:23:20 25 4
gpt4 key购买 nike

我有一个实现文本字段委托(delegate)的单元类。在这个委托(delegate)中,我正在调用一个函数来告诉 tableview 根据 indexPath 滚动到特定行。这在大多数情况下有效,但在行位于表格 View 底部时无效。单元类有一个在我的主 Controller cellForRow 方法中传入的表属性。下面的代码:

extension IR_TextCell: UITextFieldDelegate {

func textFieldDidBeginEditing(_ textField: UITextField) {
util_textField.addHightlightedBorder(textField)
if let index = table?.indexPath(for: self)
{
scrollDelegate?.scrollToMe(at: index)
}
}
}

func scrollToMe(at index: IndexPath) {
self.tableV.scrollToRow(at: index, at: .middle, animated: false)
}

我已经尝试围绕这个包装 DispatchQueue.main.async 并添加截止日期,但它没有任何区别。

我是否需要更改我的 tableview 的底部约束?

最佳答案

我的情况与您的情况有些不同,但我在滚动到靠近底部的单元格时遇到了同样的问题。它现在可能适用于您的确切情况,但我希望这对遇到此帖子的人有所帮助。我怀疑这可能是时间问题,所以我最终这样做如下:

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if indexPath.row == tableView.indexPathsForVisibleRows?.last?.row {

let scrollIndex = 0//set to your predetermined scrolled to index
let cellRect = tableView.rectForRow(at: indexPath)
let completelyVisible = tableView.bounds.contains(cellRect)

if scrollIndex >= indexPath.row && !completelyVisible {
let maxIndex = 10//number of elements in the array - 1
//in case you want a delay
DispatchQueue.main.asyncAfter(deadline: .now() + 0) {
self.tableView.scrollToRow(at: IndexPath(row: scrollIndex > maxIndex ? maxIndex : scrollIndex, section: 0), at: .middle, animated: false)
}
}

}
}

关于ios - 当所述行靠近表格 View 的底部时,ScrollToRow 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47410473/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com