简体   繁体   English

类型的viewcontroller不符合协议uitableviewdatasource

[英]type viewcontroller does not conform to protocol uitableviewdatasource

I already done the same tableview in another view but in this one could not work. 我已经在另一视图中完成了相同的tableview,但是在此视图中无法正常工作。 I'm also looking for an solution but i don't know what doesn't work 我也在寻找解决方案,但我不知道什么是行不通的

class HistoryViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { class HistoryViewController:UIViewController,UITableViewDelegate,UITableViewDataSource {

@IBOutlet weak var tableview: UITableView!

var date = ["ciao", "muori"]
var place = ["aaaa"]



override func viewDidLoad() {
    super.viewDidLoad()

    tableview.dataSource = self
    tableview.delegate = self

    // Do any additional setup after loading the view.
}


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

func tableView(tableView:UITableView, numberOfRowsInSection section:Int) -> Int
{
    return 1
}

func tableview(tableView: UITableView, cellForRowIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = self.tableview.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! HistoryCell
    cell.placeLabel.text = place[indexPath.row]
    cell.dateLabel.text = date[indexPath.row]
    return cell

}


func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{

}

someone could help me? 有人可以帮助我吗?

  • Goto Issue Navigator ( ⌘4 ). 转到问题导航器( ⌘4 )。
  • Open the disclosure triangle next to the error message. 打开错误消息旁边的显示三角形。
  • Implement the missing required methods which are displayed beneath the error message. 实现错误消息下方显示的缺少的必需方法。

And use code completion to avoid those typos. 并使用代码补全来避免这些拼写错误。

You've made a mistake in the method name: you have to implement tableView:cellForRowAtIndexPath: not tableview:cellForRowIndexPath: . 您在方法名称中犯了一个错误:您必须实现tableView:cellForRowAtIndexPath:而不是tableview:cellForRowIndexPath: Here is a correct implementation : 这是一个正确的实现:

class HistoryViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    @IBOutlet weak var tableview: UITableView!

    var date = ["ciao", "muori"]
    var place = ["aaaa"]

    override func viewDidLoad() {
        super.viewDidLoad()

        tableview.dataSource = self
        tableview.delegate = self

        // Do any additional setup after loading the view.
    }

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

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    {
        return 1
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = self.tableview.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! HistoryCell
        cell.placeLabel.text = place[indexPath.row]
        cell.dateLabel.text = date[indexPath.row]
        return cell
    }

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
    {
    }
}

Please check if 请检查是否

func tableView(tableView: UITableView!, cellForRowAtIndexPath  indexPath: NSIndexPath) -> UITableViewCell

and

func tableView(tableView:UITableView, numberOfRowsInSection section:Int)

are inserted inside class {} brackets. 插入在{}类括号内。

暂无
暂无

声明:本站的技术帖子网页,遵循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