UITableViewDataSource想要smth

时间:2016-07-01 12:19:12

标签: swift uitableview swift3 xcode8

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

P.S。在Xcode 8中,一切都很棒。我在其他4个ViewControllers中看到的问题与我使用表格相同。

1 个答案:

答案 0 :(得分:2)

Xcode 7不支持swift 3.0,并且您正在使用Swift 3.0方法UITableViewDataSource

替换:

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

使用:

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

干杯

相关问题