【问题标题】:func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) nearly matches optional requirementfunc tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) 几乎符合可选要求
【发布时间】:2016-11-04 22:38:42
【问题描述】:

我有一个这样的UIViewController

class ViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        self.tableView.dataSource = self
        self.tableView.delegate = self
    }
}

extension ViewController: UITableViewDataSource {
     // datasource methods...
}       

extension ViewController: UITableViewDelegate {
    func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
    }
}

但我收到此警告:

实例方法'tableView(:canEditRowAt:)' 几乎匹配协议'UITableViewDelegate'的可选要求'tableView(:canFocusRowAt:)'

而且我无法删除该警告。

如何删除该警告?

我必须在没有任何警告的情况下为我工作的公司提交 Xcode 项目,但我找不到如何抑制警告。

【问题讨论】:

  • 它对我来说很好用。尝试使用自动完成删除该功能并再次键入它。
  • 你使用的是 Swift 2 还是 3?
  • @penatheboss 我已经编辑了问题,添加了我实现 UITableViewDelegate 和 UITableViewDataSource 的方式
  • @rmaddy 我正在使用 Swift 3

标签: ios swift xcode uitableview


【解决方案1】:

问题在于tableView(_:canEditRowAt:) 方法来自UITableViewDataSource 协议,而不是UITableViewDelegate 协议。将其移至其他扩展程序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-26
    相关资源
    最近更新 更多