我在表格视图中添加了一个搜索栏,当用户搜索时,我希望表格视图滚动到您键入的文本.
如何使滚动视图自动滚动?
这是我尝试过的,但是我得到一个错误,说Integer不能转换为索引Path.我该怎么办?
self.tableview.scrollToRowAtIndexPath(1, atScrollPosition: UITableViewScrollPosition.Middle, animated: true)
Run Code Online (Sandbox Code Playgroud)
要么
self.tableview.scrollToNearestSelectedRowAtScrollPosition(scrollPosition: UITableViewScrollPosition.Middle, animated: true)
Run Code Online (Sandbox Code Playgroud) 我有一个UITableView,我正在尝试加载36行,然后一直向下滚动到最后一个单元格.
我试过这个:
func reloadData(){
chatroomTableView.reloadData()
chatroomTableView.scrollToBottom(true)
}
extension UITableView {
func scrollToBottom(animated: Bool = true) {
let sections = self.numberOfSections
let rows = self.numberOfRowsInSection(sections - 1)
if (rows > 0){
self.scrollToRowAtIndexPath(NSIndexPath(forRow: rows - 1, inSection: sections - 1), atScrollPosition: .Bottom, animated: true)
}
}
}
Run Code Online (Sandbox Code Playgroud)
但它只会向下滚动一半.