ios - Swift 中 TableViewCell 中的 indexPathForRowAtPoint 错误

标签 ios iphone swift uitableview uitableviewrowaction

在 UITableViewCell 的按钮内,我有这个函数,它创建一个自动滚动到下一个单元格。

var tableView = self.superview?.superview

    let point = sender.convertPoint(CGPointZero, toView : tableView)
   let indexPath = tableView.indexPathForRowAtPoint(point)!

    if indexPath.row < tableView.numberOfRowsInSection(indexPath.section) {
        let newIndexPath = NSIndexPath(forRow:indexPath.row + 1, inSection:indexPath.section)
        tableView.scrollToRowAtIndexPath(
            newIndexPath, atScrollPosition:.Top, animated: true)
    }

我在一行中出错:“let indexPath = tableView.indexPathForRowAtPoint(point)!”说:“在没有更多上下文的情况下,表达类型是模棱两可的”

你知道怎么解决吗?我想将该代码保留在我的 UITableViewCell 中。

非常感谢

最佳答案

转换superview返回的值

var tableView = self.superview?.superview as! UITableView

关于ios - Swift 中 TableViewCell 中的 indexPathForRowAtPoint 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31630693/

相关文章:

iphone - xcode 中 UIPIckerView 顶部的工具栏?

ios - 只能使用-performBlock : on an NSManagedObjectContext that was created with a queue

ios - Swift if let 在 Optional(nil) 上评估成功

ios - 使用 iOS 11 mlmodel 进行图像分类 - 使用 coremltools 和训练有素的 .caffemodel 转换问题

iphone - Float 不可转换为 CGFloat,CGFloat 不可转换为 Float

arrays - 如何将 Array<Element> 转换为数组文字

ios - 用于 View Controller 之间交互式滑动转换的简单库

iphone - 在 iPhone 上使用 opencv features2d

iOS - TableView + 按钮布局(外部)

ios - 如何更改 SceneKit 中枢轴点的位置