Ios 自定义UITableViewCell:类型为';UITableViewCell';没有成员';点编号';

Ios 自定义UITableViewCell:类型为';UITableViewCell';没有成员';点编号';,ios,swift,uitableview,Ios,Swift,Uitableview,我的错误在下面的第一个代码中,在开关的情况2中 cell.pointsNumber.text = "toto" Xcode错误:“UITableViewCell”类型的值没有成员“PointsMember” 我无法访问我的类PerformancesViewCell来填充标签。 我的演员阵容不起作用,我的手机仍然像UITableViewCell而不是performanceviewcell 提前感谢您的帮助;) 单元标识符: let thirdCellIdentifier = "thirdCel

我的错误在下面的第一个代码中,在开关的情况2中

 cell.pointsNumber.text = "toto"
Xcode错误:“UITableViewCell”类型的值没有成员“PointsMember”

我无法访问我的类
PerformancesViewCell
来填充标签。 我的演员阵容不起作用,我的手机仍然像
UITableViewCell
而不是
performanceviewcell

提前感谢您的帮助;)

单元标识符:

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
    }
自定义单元格:

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()
    }
}

问题在于这一行:

var cell: UITableViewCell!
您已将单元格声明为UITableViewCell的类型。因此,正如错误所述,
UITableViewCell
没有名为
pointsNumber
的成员

更改该行:

var pCell = tableView.dequeueReusableCellWithIdentifier(thirdCellIdentifier, forIndexPath: indexPath) as! PerformancesViewCell
pCell.pointsNumber.text = "toto"
由于您使用的是不同类型的单元,并使用开关来区分它们,因此需要将新创建的单元(pCell)重新分配给开关盒本身中的单元

cell = pCell

我建议删除
cell
var
声明,改为使用

if indexPath.row==0 {
let cell:MyCustomTVC=self.myTableView.dequeueReusableCellWithIdentifier("myCustomTVC") as! MyCustomTVC 
cell.myCustomLabel.text="asdf"
return cell
}
每种情况下。只需为每个类交换正确的类和标识符


另外,请确保使用属性检查器中的原型单元在故事板中定义了每个自定义单元类型,并且所有单元都有一个
标识符

我同意@Midhun MP的回答。通常,您应该配置自定义tableviewcell类,并在每种情况下返回它们。但如果要返回switch func之外的单元格,可以执行以下操作:

 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:
       let  performancesViewCell = tableViewProfil.dequeueReusableCellWithIdentifier(thirdCellIdentifier, forIndexPath: indexPath) as! PerformancesViewCell
        performancesViewCell.pointsNumber.text = "toto"
        cell = performancesViewCell
    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
}

这个问题不是由于您的代码,而是由于更改了视图控制器的类名而导致的

Xcode还不够智能,因此,解决方案是删除正在崩溃的视图控制器删除其类并创建一个新的视图控制器并向其添加一个新文件


我花了好几天的时间才把它修好。

为什么要用tableViewProfil而不是tableView,你在哪里声明了tableViewProfil?我在开始上课时声明了tableViewProfil。TableViewProfil是@IBOutlet弱私有变量TableViewProfil:UITableView!谢谢你的回复!如果我删除var单元格:UITableViewCell!我不能在最后还我的手机,因为开关,我需要在外面声明。@MidhunMP我想你没有读过亚瑟的全部评论。由于
开关
语句,您的解决方案导致了另一个大问题。@rmaddy:他在我回复后编辑了他的评论。谢谢你notifying@Arthur:将其分配回cell变量,我的意思是在您的切换情况下,尝试执行此cell=pCell。检查我的更新answer@MidhunMp是的,对不起,这是我第一次上stackoverflow!所以我正在学习使用它;)。是的,现在很完美,谢谢你的回复,效果很好!但是我不明白为什么我不能在PerformanceViewCell中强制转换我的变量。谢谢您的回复!如果我删除var单元格:UITableViewCell!我不能在最后还我的手机,因为开关我需要在外面声明。是的,我的所有自定义单元格和标识符都在我的故事板中定义。