我只是想在我设置的 Smiles 数组中显示名称的表格 View 。我需要声明我的单元格类“ClubCell”以扩展到 UITableViewCell,我该怎么做?
class SmileClub: UITableViewController {
var Smiles: [String] = ["Price Garrett", "Michael Bishop", "Tom Kollross", "Cody Crawford", "Ethan Bernath", "Alex Mlynarz", "Ryan Murphy", "Kelly Murphy", "Ryan Roshan", "Sean Ko"]
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> ClubCell
{
let cell: ClubCell = tableView.dequeueReusableCellWithIdentifier("ClubCell") as! ClubCell!
cell.Name.text = self.Smiles[indexPath.row] as String
return cell
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.Smiles.count
}
最佳答案
cellForRowAtIndexPath
方法的返回值需要是 UITableViewCell
,而不是 ClubCell
。
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell: ClubCell = tableView.dequeueReusableCellWithIdentifier("ClubCell") as! ClubCell!
cell.Name.text = self.Smiles[indexPath.row] as String
return cell
}
并确保您的 ClubCell
类扩展了 UITableViewCell
。
应该是:
class ClubCell : UITableViewCell
关于ios - 声明我的 CellClass 以扩展到 UITableViewCell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32727546/