ios - 声明我的 CellClass 以扩展到 UITableViewCell?

标签 ios swift uitableview

我只是想在我设置的 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/

相关文章:

ios - 如何在 Swift 中编辑动态 UITableViewCell 中的 View ?

ios - 在 UICollectionViewCell 上双击手势?

swift - 从 TableView 生成全局变量计数器

ios - 如何将视差效果应用于包含水平 UICollectionView 的 UITableView header ?

iphone - UITableView 中的第二个 View 将不会显示从 JSON 解析的数据

ruby-on-rails - Rails 和 iOS 应用程序,身份验证问题

ios - 我将如何在加载 tableView 时运行一些代码?

ios - 启用 Facebook 重大更改 2013 年 2 月 : login Does Not Work

ios - 从 Swift 函数中的异步调用返回数据

swift - 如何计算 SKScenes