UITableView 从当前位置滚动到底部 [英] UITableView scroll to bottom from current position

查看:60
本文介绍了UITableView 从当前位置滚动到底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从当前位置滚动到 tableview 中的最后一行,因为我已经尝试过这个解决方案:

How can I scroll to last row in tableview from current positon, because I have tried this solution:

self.tableView.scrollToRow(at: lastIndex.last!, at: .bottom , animated: false)


let numberOfSections = self.tableView.numberOfSections
            let numberOfRows = self.tableView.numberOfRows(inSection: numberOfSections-1)

        if numberOfRows > 0 {
            let indexPath = IndexPath(row: numberOfRows-1, section: (numberOfSections-1))
            self.tableView.scrollToRow(at: indexPath, at: .bottom, animated: animated)
        }

它不会从当前位置滚动,而是从最顶部位置滚动.即使我当前的位置是最后一行

and it doesn't scroll from the current position but from the most top position. Even though my current position is the last row

推荐答案

func scrollToLastRow() {
  let indexPath = NSIndexPath(forRow: objects.count - 1, inSection: 0)
  self.tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: .Bottom, animated: true)
}

滚动意味着,从当前位置开始.所以这段代码应该可以工作.

Scrolling means, thats from current position. So this code should work.

否则,您可以使用 scrollRectToVisible

tableView.scrollRectToVisible(tableView.rectForRowAtIndexPath(indexPath),animated: true) 

这篇关于UITableView 从当前位置滚动到底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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