【问题标题】:UITableViewDataSource wants smthUITableViewDataSource 想要什么
【发布时间】:2016-07-01 12:19:12
【问题描述】:

我在 Xcode 8 beta 中编写了 tableView 的代码,然后尝试在实际的 Xcode 7 中进行。我的下面的代码看起来是正确的,除了 UITableViewDataSource 问题。编译器说:

类型“SettingsVC”不符合协议“UITableViewDataSource”

很奇怪,因为我认为我已经实现了所有必需的方法。

class SettingsVC: UIViewController, UITableViewDelegate, UITableViewDataSource {

    @IBOutlet weak var chooseTable: UITableView!

    var tableArray = [String]()

    override func viewDidLoad() {
        tableArray = ["1", "2", "3", "4", "5"]
    }

    override func viewDidAppear(animated: Bool) {
        chooseTable.reloadData()
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return tableArray.count
    }

    func tableView(tableView: UITableView, cellForRowAt indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier(tableArray[indexPath.item], forIndexPath: indexPath)
        cell.textLabel?.text = tableArray[indexPath.row]
        return cell
    }
}

附:在 Xcode 8 中,一切都很好。我在使用表的其他 4 个 ViewController 中看到了同样的问题。

【问题讨论】:

  • 您是否检查了您尝试使用的功能的签名?

标签: swift uitableview swift3 xcode8


【解决方案1】:

Xcode 7 不支持 Swift 3.0,而您正在为 UITableViewDataSource 使用 Swift 3.0 方法

替换:

func tableView(tableView: UITableView, cellForRowAt indexPath: NSIndexPath) -> UITableViewCell {

与:

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

干杯

【讨论】:

    猜你喜欢
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 2021-03-07
    • 2012-03-17
    • 1970-01-01
    • 1970-01-01
    • 2014-11-20
    • 2022-06-17
    相关资源
    最近更新 更多