![](/img/trans.png)
[英]type viewcontroller does not conform to protocol uitableviewdatasource
[英]Type 'ViewController' does not conform to protocol '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
。
您必须实现所有必需的功能。 您可以通过命令单击UITableViewDataSource来查看它们。 为了确保您不会打错任何文字,只需复制所需的函数或开始在ViewController中键入函数的名称,其余的就由自动完成功能完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.