1
我有一個可以接受泛型類型的自定義單元。Swift 3 Generic不能轉換UITableViewCell類型的值
class MyCell<T>: UITableViewCell where T: MyCellDataSource, T: MyCellDelegate
如何使用它,或者在轉出單元時輸入或推斷它?
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
你可以做'讓電池= tableView.dequeueReusableCell(withIdentifier: 「細胞」,爲:indexPath)爲! MyCell'我認爲 – Eric
不行,那不行。這是通常的方式,我試過了。 – Axel
您不能轉換爲未指定的泛型類型,只能指定其具體版本,即指定了泛型'T'。沿着'let cell = tableView.dequeueReusableCell(withIdentifier:「cell」,for:indexPath)行的東西就像!了myCell'。 –
dfri