繁体   English   中英

Swift 3 Generic无法转换UITableViewCell类型的值

[英]Swift 3 Generic cannot convert value of type UITableViewCell

我有一个可以接受泛型类型的自定义单元格。

class MyCell<T>: UITableViewCell where T: MyCellDataSource, T: MyCellDelegate

如何在出列单元格时使用它或输入或推断它?

let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)

在Swift 3.0中,我最近使用了相同的实现。 我通过以下代码解决了这个问题。

let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as? MyCell<TName>
//Configure cell here
return cell!

希望能帮助到你

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM