【发布时间】:2016-10-05 12:42:18
【问题描述】:
我正在寻找一种方法来滚动到 UITableView 中选定的单元格,即使底部有一个空单元格。我的问题是,当表格视图底部没有单元格时,滚动事件不会滚动。
作为一种解决方法,我最终在底部创建了空单元格并删除了这些单元格,但我认为这不是一个好的解决方案。那么这个方法是怎么做到的呢?
我的代码如下所示:
func scrollToSelectedCell(indexPath: IndexPath) {
self.tableView.scrollToRow(at: indexPath, at: UITableViewScrollPosition.top, animated: true)
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath)
if (cell as? DropDownCell) != nil {
self.performSegue(withIdentifier: "showDropDownSelector", sender: cell)
} else if (cell as? PickerCell) != nil {
self.performSegue(withIdentifier: "showPickerSelector", sender: cell)
} else if let tmp_cell = cell as? TextFieldCell {
scrollToSelectedCell(indexPath: indexPath)
tmp_cell.textField.becomeFirstResponder()
}
}
【问题讨论】:
标签: ios swift uitableview uiscrollview swift3