My error is in the first code below, in the case 2 of the switch.
cell.pointsNumber.text = "toto"
Xcode error : Value of type 'UITableViewCell' has no member 'pointsNumber'
I can't access to my class PerformancesViewCell to fill the labels.
My cast doesn't work, my cell is still like a UITableViewCell rather than a PerformancesViewCell.
Thank you in advance for your help ;)
Cell Identifier:
let thirdCellIdentifier = "thirdCell"
TableView:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
var cell: UITableViewCell!
switch indexPath.row
{
case 0:
cell = tableViewProfil.dequeueReusableCellWithIdentifier(firstCellIdentifier, forIndexPath: indexPath) as UITableViewCell
cell.backgroundView = nil
cell.backgroundColor = UIColor.clearColor()
break;
case 1:
cell = tableViewProfil.dequeueReusableCellWithIdentifier(secondCellIdentifier, forIndexPath: indexPath) as! DivisionsViewCell
break;
case 2:
cell = tableViewProfil.dequeueReusableCellWithIdentifier(thirdCellIdentifier, forIndexPath: indexPath) as! PerformancesViewCell
cell.pointsNumber.text = "toto"
case 3:
cell = tableViewProfil.dequeueReusableCellWithIdentifier(fourthCellIdentifier, forIndexPath: indexPath) as! ChampionsViewCell
break;
case 4:
cell = tableViewProfil.dequeueReusableCellWithIdentifier(fifthCellIdentifier, forIndexPath: indexPath) as UITableViewCell
break;
default:
cell = tableViewProfil.dequeueReusableCellWithIdentifier(fifthCellIdentifier, forIndexPath: indexPath) as UITableViewCell
break;
}
return cell
}
CustomCell:
import UIKit
class PerformancesViewCell: UITableViewCell
{
@IBOutlet weak var pointsNumber: UILabel!
@IBOutlet weak var challengesSucceed: UILabel!
@IBOutlet weak var bestPosition: UILabel!
@IBOutlet weak var averagePosition: UILabel!
@IBOutlet weak var challengeCreation: UILabel!
override func awakeFromNib()
{
super.awakeFromNib()
}
}
The issue is because of this line:
var cell: UITableViewCell!
You declared cell as type of UITableViewCell . So as the error states the UITableViewCell has no member named pointsNumber.
Change that line:
var pCell = tableView.dequeueReusableCellWithIdentifier(thirdCellIdentifier, forIndexPath: indexPath) as! PerformancesViewCell
pCell.pointsNumber.text = "toto"
Since you are using different type of cells and using a switch to distinguish between them, you need to assign the newly created cell(pCell) back to cell in the switch case itself.
cell = pCell
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With