无法将类型"UITableViewCell"的值强制转换为"AppName.CustomCellName" [英] Could not cast value of type 'UITableViewCell' to 'AppName.CustomCellName'
问题描述
我正在尝试创建一个自定义单元格,该单元格可以在点击时扩展.我正在使用这个github示例: https://github.com/rcdilorenzo/Cell-Expander
I am trying to create a custom cell that expands on tap. I am using this github example: https://github.com/rcdilorenzo/Cell-Expander
此行给出运行时错误SIGABRT:
This line gives runtime error 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).
}
我也检查了这篇文章的答案,遵循了三个步骤,但是没有运气: 无法将'UITableViewCell'类型的值强制转换为'( AppName).(CustomCellName)'
I also checked answer from this post, followed three steps, but no luck: Could not cast value of type 'UITableViewCell' to '(AppName).(CustomCellName)'
我的自定义单元格类如下:
My custom cell class looks like this:
import UIKit
class EventTableViewCell : UITableViewCell {
...
}
cellForRowAtIndexPath:
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
}
}
请帮助.
推荐答案
我的viewDidLoad中有self.tableView.registerClass(UITableViewCell.self,forCellReuseIdentifier:" eventCell)"
"I have self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "eventCell") in my viewDidLoad"
这可能会覆盖您在情节提要中设置的值.尝试删除此行,或将其更改为self.tableView.registerClass(EventTableViewCell.self, forCellReuseIdentifier: "eventCell")
.
That's probably overriding the value you set in the storyboard. Try removing this line, or change it to self.tableView.registerClass(EventTableViewCell.self, forCellReuseIdentifier: "eventCell")
.
这篇关于无法将类型"UITableViewCell"的值强制转换为"AppName.CustomCellName"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!