Reputation: 1
I already done the same tableview in another view but in this one could not work. I'm also looking for an solution but i don't know what doesn't work
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?
Upvotes: 0
Views: 1561
Reputation: 285079
And use code completion to avoid those typos.
Upvotes: 3
Reputation: 2459
You've made a mistake in the method name: you have to implement tableView:cellForRowAtIndexPath:
not 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)
{
}
}
Upvotes: 1
Reputation: 134
Please check if
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
and
func tableView(tableView:UITableView, numberOfRowsInSection section:Int)
are inserted inside class {} brackets.
Upvotes: 0