ios - 调用 reloadData 时,UITableView 有不需要的动画

标签 ios swift uitableview

我有一个 UITableView,如果我稍微滚动一下内容然后调用 reloadData,当数据重新加载时,表格会显示滚动动画。

enter image description here

viewDidLoad 中调用的表设置:

func setupTableView() {
        tableView.register(UINib(nibName: "AnswerCell", bundle: nil), forCellReuseIdentifier: "AnswerCell")
        tableView.register(UINib(nibName: "QuizDescription", bundle: nil), forCellReuseIdentifier: "QuizDescription")
        tableView.register(UINib(nibName: "QuestionNumberCell", bundle: nil), forCellReuseIdentifier: "QuestionNumberCell")
        tableView.tableFooterView = UIView()
        tableView.estimatedRowHeight = 135
        tableView.rowHeight = UITableViewAutomaticDimension
        tableView.delegate = self
        tableView.dataSource = self
    }

当提交按钮被按下时 tableView.reloadData() 被调用。知道为什么会出现这个动画吗?我能做些什么来阻止它?

最佳答案

在调用reloadData 之前,您需要先重置位置。

 tableView.contentOffset = .zero

关于ios - 调用 reloadData 时,UITableView 有不需要的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46881543/

相关文章:

ios - swift AVCapturePhotoOutput capturePhoto 挂起预览

ios - 我如何创建不带动画的曲线 UIView/UIImageView?

iOS - PLIST - 从 plist 内访问其他 plist 值

ios - 格式化非英文数字

ios - Xcode 11 重新编译太多

ios - 按 editButtonItem 不会启用/禁用删除滑动

android - PhoneGap 体验

json - Swift:如何在异步 urlsession 函数中返回一个值?

ios - UITableViewCell.SeparatorStyle.none 是如何工作的?

ios - iOS5 中我的 UITableView 出现 dequeueReusableCellWithIdentifier 错误