[英]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? 有人可以帮助我吗?
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.