我只是想在我设置的微笑数组中显示名字的表格视图。我需要声明我的单元格类“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

10-08 06:04