无法将"UITableViewCell"类型的值转换为"AppName.CustomCellName"

Asy*_*nc- 5 xcode uitableview ios swift2

我正在尝试创建一个自动扩展的自定义单元格.我正在使用这个github示例:https://github.com/rcdilorenzo/Cell-Expander

这一行给出了运行时错误SIGABRT:

override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
    (cell as! EventTableViewCell).watchFrameChanges()
    //Could not cast value of type 'UITableViewCell' (0x105aa1b80) to 'AppName.EventTableViewCell' (0x104287fe0).
}
Run Code Online (Sandbox Code Playgroud)

我也检查了这篇文章的答案,接着是三个步骤,但没有运气: 无法将'UITableViewCell'类型的值转换为'(AppName).(CustomCellName)'

我的自定义单元类看起来像这样:

import UIKit

class EventTableViewCell : UITableViewCell {
...
}
Run Code Online (Sandbox Code Playgroud)

的cellForRowAtIndexPath:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier( "eventCell", forIndexPath: indexPath)

    let date = self.eventArray[indexPath.row].startTime
    let calendar = NSCalendar.currentCalendar()
    let minutes = calendar.component(NSCalendarUnit.Minute, fromDate: date)
    var minutesString: String
    if (minutes == 0) {
        minutesString = "00"
    } else {
        minutesString = String(calendar.component(NSCalendarUnit.Minute, fromDate: date))
    }
    let hours = calendar.component(NSCalendarUnit.Hour, fromDate: date)
    cell.textLabel?.text = self.eventArray[indexPath.row].title + " - \(hours):\(minutesString)"

    return cell
    }
}
Run Code Online (Sandbox Code Playgroud)

请帮忙.

Gre*_*own 17

"我的viewDidLoad中有self.tableView.registerClass(UITableViewCell.self,forCellReuseIdentifier:"eventCell")"

这可能会覆盖您在故事板中设置的值.尝试删除此行,或将其更改为self.tableView.registerClass(EventTableViewCell.self, forCellReuseIdentifier: "eventCell").