简体   繁体   English

我的UIViewController“不符合协议:'UITableViewDataSource'”

[英]My UIViewController “does not conform to protocol: 'UITableViewDataSource'”

So, first of all, I realize that there are many questions like this, and I've gone through at least 13 (I've been counting), but my error never seems to go away. 所以,首先,我意识到有很多这样的问题,而且我已经经历了至少13个(我一直在数),但是我的错误似乎从未消失。 I have some code in Swift for a UITableView that should list what is in an array. 我在Swift中有一些用于UITableView的代码,该代码应列出数组中的内容。 Sadly, I get the error that I wrote in the title: ... "does not conform to protocol: 'UITableViewDataSource'". 可悲的是,我得到了我在标题中写的错误:...“不符合协议:'UITableViewDataSource'”。 Here is my code. 这是我的代码。 Any idea why it doesn't work? 知道为什么它不起作用吗?

import UIKit

class history: UIViewController,UITableViewDataSource, UITableViewDelegate {
    @IBOutlet weak var table: UITableView!
    var items: [String] = ["One", "two", "three", "four", "five"]

    func tableView(tableView: UITableView!, numberofRowsInSection section: Int)->Int{
        return items.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)->UITableViewCell {
        let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "acell")
        cell.textLabel!.text = items[indexPath.row]

        return cell
    }

    override func prefersStatusBarHidden() -> Bool {
        return true
    }


}

Thanks a lot in advance. 非常感谢。

You have two issues with this function: 此功能有两个问题:

func tableView(tableView: UITableView!, numberofRowsInSection section: Int)->Int{
                                     ^        ^
                            get rid of        Of, not of

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

相关问题 ViewController不符合协议UITableViewDataSource - ViewController does not conform to protocol UITableViewDataSource ImagesTabViewController'不符合协议'UITableViewDataSource' - ImagesTabViewController' does not conform to protocol 'UITableViewDataSource' 类型的viewcontroller不符合协议uitableviewdatasource - type viewcontroller does not conform to protocol uitableviewdatasource 错误:类型“ UserAccView”不符合协议“ UITableViewDataSource” - error : type “UserAccView” does not conform to protocol 'UITableViewDataSource' iOS:'MyViewController'不符合协议'UITableViewDataSource' - iOS : 'MyViewController' does not conform to protocol 'UITableViewDataSource' 自定义UITableViewCell不符合协议UITableViewDataSource吗? - Custom UITableViewCell does not conform to protocol UITableViewDataSource? UITableView不符合协议UITableViewDataSource错误 - UITableView does not conform to protocol UITableViewDataSource error 类型TypeViewOne不符合协议UITableViewDataSource - type TypeViewOne 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'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM