如何滚动到UITableView的确切末端? [英] How to scroll to the exact end of the UITableView?

查看:79
本文介绍了如何滚动到UITableView的确切末端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITableView,其中装有动态高度的单元格.从视图控制器中推送视图控制器时,我希望表格滚动到底部.

I have a UITableView that is populated with cells with dynamic height. I would like the table to scroll to the bottom when the view controller is pushed from view controller.

我已经尝试过contentOffsettableView scrollToRowAtIndexPath,但仍然无法得到我想要的完美解决方案.

I have tried with contentOffset and tableView scrollToRowAtIndexPath but still I am not getting the perfect solution for exactly I want.

任何人都可以帮助我解决此问题吗?

Can anyone please help me fix this issue?

这是我要滚动的代码:

let indexPath = NSIndexPath(forRow: commentArray.count-1, inSection: 0)
tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: .Bottom, animated: true)

推荐答案

对于 Swift 3.0

编写一个函数:

func scrollToBottom(){
    DispatchQueue.main.async {
        let indexPath = IndexPath(row: self.dataArray.count-1, section: 0)
        self.tableView.scrollToRow(at: indexPath, at: .bottom, animated: true)
    }
}

并在重新加载表格视图数据后调用它

and call it after you reload the tableview data

tableView.reloadData()
scrollToBottom()

这篇关于如何滚动到UITableView的确切末端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆