UITableView在调用reloadData时产生了不必要的动画。

4

我有一个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()。有什么想法为什么会出现这种动画?我该怎么做才能停止它?

你解决了吗?我也有同样的问题。 - Igor Kulman
2个回答

0

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

 tableView.contentOffset = .zero

{btsdaf} - Kex

0

您可以尝试在performWithoutAnimation:块中重新加载tableview:

UIView.performWithoutAnimation {
    self.tableView.reloadData()
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接