types'ViewController'不符合协议'UITableViewDataSource'

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

你在numberOfRowsInSection函数中犯了一个错字。 它是UITableViewDataSource协议的必需函数。 它应该是

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

你已经键入了numberofRowInsection

你必须实现所有必需的function。 你可以通过点击UITableViewDataSource命令来看到它们。 为了确保不要input任何错字,只需复制所需的函数或者在ViewController中input函数的名称,然后自动完成。