【问题标题】:How do I fix "method does not override any method from its superclass."?如何修复“方法不会覆盖其超类中的任何方法。”?
【发布时间】:2015-12-16 18:45:11
【问题描述】:

覆盖 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cellIdentifier = "Cell"
    let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! CustomTableViewCell

    // Configure the cell...
    cell.nameLabel.text = restaurantNames[indexPath.row]
    cell.thumbnailImageView.image = UIImage(named: restaurantImages[indexPath.row])
    cell.locationLabel.text = restaurantLocations[indexPath.row]
    cell.typeLabel.text = restaurantTypes[indexPath.row]

    cell.accessoryType = restaurantIsVisited[indexPath.row] ? .Checkmark : .None

    // Circular image
    cell.thumbnailImageView.layer.cornerRadius = cell.thumbnailImageView.frame.size.width / 2
    cell.thumbnailImageView.clipsToBounds = true

    return cell
}

【问题讨论】:

  • 如果我从 editActionsForRowAtIndexPath 函数中删除覆盖,我会收到冲突错误
  • 您的方法签名很可能有错字。

标签: ios uitableview overriding


【解决方案1】:

你应该分享你的全部课程。虽然,您似乎没有覆盖基类中的任何方法。只需从您的方法中删除 override 关键字,或确定存在具有相同签名(您想要覆盖)的 Overridable 方法的正确 BaseClass,然后正确使用 extends 关键字。

我认为你应该先用谷歌搜索这些术语:MethodOverriding, BaseClass(or SuperClass)

【讨论】:

  • 是的,我做到了。 editActionsForRowAtIndexPath 没有超类。我仍然遇到冲突错误
【解决方案2】:

只需从您的 editActionsForRowAtIndexPathcommitEditingStyle 函数声明中删除 override 字样。

【讨论】:

  • 不,这没有帮助。 @commiteditingstyle 它修复了它供我添加,我需要用于共享和删除手势的覆盖功能
  • @Ebin,您的回复没有意义。 - tableView:commitEditingStyle:forRowAtIndexPath: 是表视图数据源方法,- tableView:editActionsForRowAtIndexPath: 是表视图委托方法。除非您将实现这些方法的视图控制器类子类化,否则您确实需要覆盖限定符。 Override 告诉编译器父类实现了一个方法,但您的子类提供了该方法的不同版本。
  • 你得到的错误明确告诉你父类没有实现方法。 (你没有说哪些方法给出了错误。)
  • 嗨@DuncanC 我已经编辑并添加了整个代码。请问你能告诉我问题是什么吗?
  • 我想通过向左滑动手势来添加分享按钮。在哪里可以看到更多和删除按钮
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-12-08
  • 1970-01-01
  • 1970-01-01
  • 2019-11-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多