Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom UITableViewCell: Value of type 'UITableViewCell' has no member 'pointsNumber'

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()
    }
}
like image 312
Arthur Avatar asked Jan 26 '26 10:01

Arthur


1 Answers

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
like image 106
Midhun MP Avatar answered Jan 28 '26 00:01

Midhun MP