[英]Issue with Swift subclassing a class
I have a table view cell create like this where the code crashes on: 我有一个这样创建的表视图单元,其中的代码崩溃了:
let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier") as! TestedViewCell;
cell.delegate = self;
I have the code to create the subclass like so: 我有这样的代码来创建子类:
class TestedViewCell: SwipeTableViewCell
{
var animator: Any?
}
The above lines are in the same file with the kit imported. 以上几行与导入的工具包在同一文件中。 I then get the error like so:
然后我得到这样的错误:
Could not cast value of type 'SwipeCellKit.SwipeTableViewCell' (0x100121a60) to 'app.TestedViewCell' (0x100076f40).
Did I subclass it wrong? 我把它子类化了吗? Thanks.
谢谢。
尝试注册TestedViewCell
在ViewDidLaod
self.tableView.registerClass(TestedViewCell.self, forCellReuseIdentifier: "reuseIdentifier")
From your error 从你的错误
Could not cast value of type 'SwipeCellKit.SwipeTableViewCell' (0x100121a60) to 'app.TestedViewCell' (0x100076f40).
无法将类型“ SwipeCellKit.SwipeTableViewCell”(0x100121a60)的值强制转换为“ app.TestedViewCell”(0x100076f40)。
it is clear that your are trying to Cast SwipeTableViewcell as TestedViewCell. 很明显,您正在尝试将SwipeTableViewcell强制转换为TestedViewCell。 TestedViewCell is subclass of your SwipeTableViewcell .
TestedViewCell是SwipeTableViewcell的子类。 Issue might be in your register cell.
问题可能出在您的注册单元中。 You need to register cell in viewDidLoad as
您需要将viewDidLoad中的单元格注册为
self.tableView.registerClass(TestedViewCell.self, forCellReuseIdentifier: "testedViewCell")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.