Art*_*hur 3 uitableview ios swift
我的错误在下面的第一个代码中,在交换机的情况2中.
cell.pointsNumber.text = "toto"
Run Code Online (Sandbox Code Playgroud)
Xcode错误:'UITableViewCell'类型的值没有成员'pointsNumber'
我无法访问我的班级PerformancesViewCell来填写标签.我的演员不行,我的单元仍然像一个UITableViewCell而不是一个PerformancesViewCell.
预先感谢您的帮助 ;)
小区标识符:
let thirdCellIdentifier = "thirdCell"
Run Code Online (Sandbox Code Playgroud)
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
}
Run Code Online (Sandbox Code Playgroud)
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()
}
}
Run Code Online (Sandbox Code Playgroud)
问题是因为这一行:
var cell: UITableViewCell!
Run Code Online (Sandbox Code Playgroud)
您将cell声明为UITableViewCell的类型.因此错误表明UITableViewCell没有成员命名pointsNumber.
改变那一行:
var pCell = tableView.dequeueReusableCellWithIdentifier(thirdCellIdentifier, forIndexPath: indexPath) as! PerformancesViewCell
pCell.pointsNumber.text = "toto"
Run Code Online (Sandbox Code Playgroud)
由于您使用的是不同类型的单元并使用开关来区分它们,因此需要将新创建的单元(pCell)分配回交换机外壳中的单元.
cell = pCell
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13361 次 |
| 最近记录: |