【问题标题】:Automatic scroll to the next cell in a PFQueryTableViewController in Swift在 Swift 中自动滚动到 PFQueryTableViewController 中的下一个单元格
【发布时间】:2015-07-25 10:28:09
【问题描述】:

我在 Swift 中有一个带有 PFTableViewCells 的 PFTableViewController。

在每个 TableViewCell(高度为屏幕大小的 80%)中,都有一个按钮。我希望当用户选择按钮时,会自动滚动到下一个 TableViewCell。

知道我该怎么做吗?

非常感谢

【问题讨论】:

    标签: ios iphone swift uitableview uitableviewrowaction


    【解决方案1】:

    只需确定 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)
        }
    
    }
    

    【讨论】:

    • 太棒了!但是,我如何调用 tableView.indexPath,因为我在我的 TableViewCell 中并且它不知道 tableView?
    • 那是因为我的 buttonTapped 方法在我的 TableViewCell 类中
    • 它属于controller,而不是cell。该单元格是一个视图,不应操纵控制器管理的其他视图(在本例中为表格视图)。
    • 好的,谢谢。我添加了: var tableView = self.superview let point = sender.convertPoint(CGRectZero, toView:tableView) 仍然给我错误:“无法使用类型参数“(CGRect,ToView:?UIView'跨度>
    • 你知道如何解决这个问题吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-03
    • 2022-06-25
    • 1970-01-01
    相关资源
    最近更新 更多