ios - 加载视图控制器时如何滚动到特定的 UITableViewCell 顶部到 UITableView 顶部
问题描述
我想在加载视图控制器时将特定的表格视图单元格滚动到顶部
这种方法工作正常。但是当单元格高度动态变化时,单元格不会滚动到顶部,而是滚动到中心
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
}
解决方案
scrollToRow
你应该打电话viewWillAppear
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
tblList.scrollToRow(at: Your_desired_indexPath, at: .top, animated: true)
}
推荐阅读
- android - 获取文件路径的所有子文件夹android kotlin
- elasticsearch - 应用聚合后过滤掉弹性搜索中的术语聚合桶
- c# - Linq 查询要么给我重复记录,要么只给我一条记录
- html - Django 模板语法错误(无效的块标签)
- python-3.x - 定制的神经网络为 iris 数据集提供 0 精度
- javascript - Flutter PWA Service Worker 离线设置
- css - 父组件的类在子组件中不起作用
- yocto - 将 sshd_config 文件替换为 Yocto 中的自定义文件
- javascript - 解构赋值以将对象作为函数的参数传递
- javascript - Mongodb 查询 vs JavaScript 数组方法性能