简体   繁体   English

类型“ ViewController”不符合协议“ 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
    }

}

You made an typo in numberOfRowsInSection function. 您在numberOfRowsInSection函数中输入了错误。 It is a required function of the UITableViewDataSource protocol. 它是UITableViewDataSource协议的必需功能。 It should be 它应该是

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

You have typed numberofRowInsection instead. 您改为键入numberofRowInsection

You have to implement all the required functions. 您必须实现所有必需的功能。 You can see them by command clicking on the UITableViewDataSource. 您可以通过命令单击UITableViewDataSource来查看它们。 To make sure you don't make any typo, just copy the required functions or start typing in the ViewController the name of the function and autocompletion should do the rest. 为了确保您不会打错任何文字,只需复制所需的函数或开始在ViewController中键入函数的名称,其余的就由自动完成功能完成。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型的viewcontroller不符合协议uitableviewdatasource - type viewcontroller does not conform to protocol uitableviewdatasource 类型“ ViewController”不符合协议“ UITableViewDataSource” - Type “ViewController” does not conform to protocol 'UITableViewDataSource" 类型“ViewController”不符合协议“UITableViewDataSource” - Type 'ViewController' does not conform to protocol 'UITableViewDataSource' 类型“ ViewController”不符合协议“ UITableViewDataSource” - Type'ViewController' does not conform to protocol 'UITableViewDataSource' ViewController不符合协议UITableViewDataSource - ViewController does not conform to protocol UITableViewDataSource Xcode类型“ ViewController”中出现错误不符合协议“ UITableViewDataSource” - Getting error in Xcode type “ViewController” does not conform to protocol“UITableViewDataSource” 与“类型'ViewController'不符合协议'UITableViewDataSource'”相关的编译和构建错误 - Compile & Build error related to “Type 'ViewController' does not conform to protocol 'UITableViewDataSource'” 错误:类型“ UserAccView”不符合协议“ UITableViewDataSource” - error : type “UserAccView” does not conform to protocol 'UITableViewDataSource' 类型TypeViewOne不符合协议UITableViewDataSource - type TypeViewOne does not conform to protocol UITableViewDataSource 收到错误“ Type ViewController不符合协议'UITableViewDataSource…”,即使我具有必需的功能 - Receiving error “Type ViewController does not conform to protocol 'UITableViewDataSource…” even though I have the required functions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM