【发布时间】:2015-10-30 12:47:37
【问题描述】:
我正在尝试创建一个可在点击时展开的自定义单元格。我正在使用这个 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).
}
我还检查了这篇文章的答案,遵循了三个步骤,但没有运气: Could not cast value of type 'UITableViewCell' to '(AppName).(CustomCellName)'
我的自定义单元格类如下所示:
import UIKit
class EventTableViewCell : UITableViewCell {
...
}
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
}
}
请帮忙。
【问题讨论】:
-
显示方法 cellForRowAtIndexPath 的代码
-
@MobileMon 编辑了问题^
标签: ios xcode uitableview swift2