swift - UITableViewDataSource 想要 smth

标签 swift uitableview swift3 xcode8

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

Type 'SettingsVC' does not conform to protocol '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 个使用表的 ViewControllers 中看到了同样的问题。

最佳答案

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 {

干杯

关于swift - UITableViewDataSource 想要 smth,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38145269/

相关文章:

Xcode Beta 经常挂起/SourceKitService 高 cpu

ios - 刷新 UITableView 中的分页数据

ios - 场景编辑器中的 SKSpriteNode 未使用分配的自定义类

swift - 当 View 改变时计时器终止

swift - 在 segue 之间推送信息是行不通的

ios - 上下文成员没有关联值

ios - 更改角标(Badge)在 TDBadgedCell 中的位置

swift - 如何在 UITableViewCell 类中使用prepare for segue

macos - 将 AppleScript 转换为 SwiftAutomation

快速 cookies urlsession 请求