gpt4 book ai didi

ios - 添加标题 View 后,滚动到 UITableView 的底部导致 NSException

转载 作者:行者123 更新时间:2023-11-28 15:52:34 24 4
gpt4 key购买 nike

我有一个方法可以将我的 UITableView 滚动到底部:

func tableViewScrollToBottom(_ animated: Bool) {

let delay = 0.1 * Double(NSEC_PER_SEC)
let time = DispatchTime.now() + Double(Int64(delay)) / Double(NSEC_PER_SEC)

DispatchQueue.main.asyncAfter(deadline: time, execute: {
print(self.tview.numberOfRows(inSection: 0))
print(self.tview.numberOfSections)
let indexPath = IndexPath(row: self.tview.numberOfRows(inSection: 0), section: self.tview.numberOfSections)
print(indexPath)
print("it will crash now")
self.tview.scrollToRow(at: indexPath, at: .bottom, animated: animated)

})
}

它以前运行良好,但是当我添加标题 View 时 - 它崩溃了。

我在控制台看到:

8
1
[1, 8]
it will crash now

所以我不明白为什么这一行:

self.tview.scrollToRow(at: indexPath, at: .bottom, animated: animated)

导致崩溃。我在这里缺少什么?

最佳答案

你有问题

let indexPath = IndexPath(row: self.tview.numberOfRows(inSection: 0), section: self.tview.numberOfSections)

尝试做 -1

let indexPath = IndexPath(row: self.tview.numberOfRows(inSection: 0)-1, section: self.tview.numberOfSections-1)

关于ios - 添加标题 View 后,滚动到 UITableView 的底部导致 NSException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42124677/

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