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

Wil*_*ung 0 uitableview ios 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
    }

}
Run Code Online (Sandbox Code Playgroud)

rak*_*hbs 5

你在numberOfRowsInSection功能上打错了.它是协议的必需功能UITableViewDataSource.它应该是

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return alphNames.count
}
Run Code Online (Sandbox Code Playgroud)

你输入了numberofRowInsection.