mercredi 26 novembre 2014

tableview custom cell: use of undeclared type


Vote count:

0




I'm setting up custom cell for a tableview and got it almost work properly except some annoying errors. So I setup a prototype cell in storyboard with identifier: RankingCell and class: RankingCell.


I setup a very basic class file : RankingCell.swift



import Foundation
import UIKit


class RankingCell: UITableViewCell {
@IBOutlet var firstName: UILabel!
@IBOutlet var lastName: UILabel!
}


The outlets are correctly linked to field inside the custom cell. Now here is the view controller file:



class RankingViewController: UIViewController, UITableViewDelegate {

var testArray = ["Ben", "rob"]
var testArray2 = ["mel", "duval"]


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

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

let cell = tableView.dequeueReusableCellWithIdentifier("RankingCell") as RankingCell //Error I here

cell.firstName.text = testArray[indexPath.row]
cell.lastName.text = testArray2[indexPath.row]

return cell
}

override func viewDidLoad() {
super.viewDidLoad()
tableView.reloadData() //Error II here


}

}


The error I outlined by the complier is "use of undeclared type 'RankingCell'". What's weird is that when I compile, it compiles with no problem, and even displays correct data in the cells. Still I would prefer to do things properly and get ride of the outlined error.


The second error is in viewdidload. I simplified the code in the example, but I pull data from a backend, and once I have it, I need to reload the table so I put there tableView.reloadData() which trigger error: "(UITableView, numberOfRowsInSection: Int) -> Int' does not have a member named 'reloadData'". Thus I can't have the table reload with appropriate data. Maybe you know how to have data reloaded properly from viewdidload ?


Please answer in swift.



asked 1 min ago







tableview custom cell: use of undeclared type

Aucun commentaire:

Enregistrer un commentaire