gpt4 book ai didi

ios - 加载 View Controller 时如何滚动到特定的 UITableViewCell 顶部到 UITableView 顶部

转载 作者:行者123 更新时间:2023-11-30 11:29:36 35 4
gpt4 key购买 nike

我想在加载 View Controller 时将特定的表格 View 单元格滚动到顶部

这个方法运行良好。但是当单元格高度动态变化时,单元格不会滚动到顶部,而是滚动到中心

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCell(withIdentifier: "slideshowTableViewCell", for: indexPath) as! slideshowTableViewCell

if(self.scrollEnabled){

let indexPath = NSIndexPath(row: self.imageId, section: 0)
self.slideshowView.scrollToRow(at: indexPath as IndexPath, at: .top, animated: true)


self.scrollEnabled = false
}

最佳答案

您应该在 viewWillAppear 上调用 scrollToRow

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

tblList.scrollToRow(at: Your_desired_indexPath, at: .top, animated: true)
}

关于ios - 加载 View Controller 时如何滚动到特定的 UITableViewCell 顶部到 UITableView 顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50384833/

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