[英]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.