问题与斯威夫特继承一个类
问题描述:
我有一个表视图单元格创建这样在代码崩溃上:问题与斯威夫特继承一个类
let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier") as! TestedViewCell;
cell.delegate = self;
我的代码,以创建像这样子类:
class TestedViewCell: SwipeTableViewCell
{
var animator: Any?
}
的上面的行与导入的工具包位于同一个文件中。然后我得到这样的错误:
Could not cast value of type 'SwipeCellKit.SwipeTableViewCell' (0x100121a60) to 'app.TestedViewCell' (0x100076f40).
我的子类错了吗?谢谢。
答
尝试ViewDidLaod
self.tableView.registerClass(TestedViewCell.self, forCellReuseIdentifier: "reuseIdentifier")
答
注册TestedViewCell
从你的错误
无法投类型的值 'SwipeCellKit.SwipeTableViewCell' (0x100121a60)为 'app.TestedViewCell'(0x100076f40) 。
很明显,您正试图将SwipeTableViewcell作为TestedViewCell投入使用。 TestedViewCell是您的SwipeTableViewcell的子类。问题可能在您的注册单元中。你需要在viewDidLoad中注册单元格为
self.tableView.registerClass(TestedViewCell.self, forCellReuseIdentifier: "testedViewCell")
是SwipeTableViewCell我是UItableViewCell的sublcass? –
它是从这个项目:https://github.com/SwipeCellKit/SwipeCellKit – cdub
尝试注册单元格在ViewDidLaod self.tableView.registerClass(TestedViewCell.self,forCellReuseIdentifier:“reuseIdentifier”) – KKRocks