【发布时间】:2015-07-25 10:28:09
【问题描述】:
我在 Swift 中有一个带有 PFTableViewCells 的 PFTableViewController。
在每个 TableViewCell(高度为屏幕大小的 80%)中,都有一个按钮。我希望当用户选择按钮时,会自动滚动到下一个 TableViewCell。
知道我该怎么做吗?
非常感谢
【问题讨论】:
标签: ios iphone swift uitableview uitableviewrowaction
我在 Swift 中有一个带有 PFTableViewCells 的 PFTableViewController。
在每个 TableViewCell(高度为屏幕大小的 80%)中,都有一个按钮。我希望当用户选择按钮时,会自动滚动到下一个 TableViewCell。
知道我该怎么做吗?
非常感谢
【问题讨论】:
标签: ios iphone swift uitableview uitableviewrowaction
只需确定 indexPath 并滚动到下一个 indexPath。此示例假设一个没有部分的平面表。
func buttonTapped(sender: UIButton) {
let point = sender.convertPoint(CGPointZero, toView:tableView)
let indexPath = tableView.indexPathForRowAtPoint(point)!
// check for last item in table
if indexPath.row < tableView.numberOfRowsInSection(indexPath.section) {
let newIndexPath = NSIndexPath(forRow:indexPath.row + 1 inSection:indexPath.section)
tableView.scrollToRowAtIndexPath(
newIndexPath, atScrollPosition:.Top, animated: true)
}
}
【讨论】: