【问题标题】:indexPathForRowAtPoint Error in a TableViewCell in SwiftSwift 中 TableViewCell 中的 indexPathForRowAtPoint 错误
【发布时间】:2015-07-25 20:15:04
【问题描述】:

在 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)
    }

我有一个错误:“让 indexPath = tableView.indexPathForRowAtPoint(point)!”说:“没有更多上下文,表达的类型是模棱两可的”

您知道如何解决它吗?我想将该代码保留在我的 UITableViewCell 中。

非常感谢

【问题讨论】:

    标签: ios iphone swift uitableview uitableviewrowaction


    【解决方案1】:

    投射superview返回的值

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

    【讨论】:

    • 感谢您的回答!但是,即使我将表达式转换为 NSIndexPath let indexPath = tableView.indexPathForRowAtPoint(point)!作为? NSIndexPath 还是报错:“Type of expression is ambiguous without more context”
    • [更新] 你知道为什么吗?
    • @skifen128 'let indexPath: NSIndexPath 怎么样? = tableView.indexPathForRowAtPoint(point)!'
    • 试试这个'var tableView = self.superview?.superview as! UITableView' 并删除我告诉你的那些东西。它现在应该可以工作了。
    • 太棒了!谢谢你!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-15
    • 1970-01-01
    • 2019-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多