类型'ViewController'不符合协议'UITableViewDataSource'

时间:2015-02-04 13:22:36

标签: ios uitableview swift

import UIKit

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    var alphNames = ["ABC","DEF","GHI","JKL","MNO","PQR","STU"]

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

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
           let cellIdentifier = "Cell"
           let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath : indexPath) as UITableViewCell

           //Configure the cell...
           cell.textLabel?.text = departmentNames[indexPath.row]
           return cell
    }

}

1 个答案:

答案 0 :(得分:5)

你在numberOfRowsInSection函数中输了一个拼写错误。它是UITableViewDataSource协议的必需函数。它应该是

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

您已输入numberofRowInsection