'UITableViewCell?' 类型的值没有成员 'delegate'

Value of type 'UITableViewCell?' has no member 'delegate'

我正在 TableViewCell class 中创建自定义委托并在 tableView class 中调用它,但不知道为什么会出现此错误。

表格视图Class:-

 //Cell For Row at indexPath
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
    if (0 == indexPath.section)
    {
        let cell = tableView.dequeueReusableCell(withIdentifier: "FirstRowCell") as! FirstRowCell
        cell.btnReview.addTarget(self, action: #selector(GotoReview), for: UIControlEvents.touchUpInside)

        //cell.
        return cell
    }

    else if ( 1 == indexPath.section)
    {
        let identifier = "TableCollectionCell"
        var tableCollectionCell = tableView.dequeueReusableCell(withIdentifier: identifier)
        if(tableCollectionCell == nil)
        {
            let nib:Array = Bundle.main.loadNibNamed("TableCollectionCell", owner: self, options: nil)!
            tableCollectionCell = nib[0] as! TableCollectionCell

            //Delegate
            tableCollectionCell.delegate = self

        }

        return tableCollectionCell!
    }

    else
    {
        let identifier = "BrandImagesTableCell"
        var brandImagesTableCell = tableView.dequeueReusableCell(withIdentifier: identifier)
        if(brandImagesTableCell == nil)
          {
            let nib:Array = Bundle.main.loadNibNamed("BrandImagesTableCell", owner: self, options: nil)!
            brandImagesTableCell = nib[0] as? BrandImagesTableCell
          }
        return brandImagesTableCell!
    }
}


extension HomeViewController : CollectionViewCellTap
{
  func didTapCollectionViewCell(indexPath: Int) {
    let gotoCreateGroup =  self.storyboard?.instantiateViewController(withIdentifier: "CreateGroupView") as! CreateGroupView

    self.present(gotoCreateGroup, animated: true, completion: nil)
  }
}

从 TableViewCell 调用 class :-

  protocol CollectionViewCellTap
  {
   func didTapCollectionViewCell(indexPath : Int)

  }

  class TableCollectionCell: UITableViewCell {

@IBOutlet weak var collectionView: UICollectionView!

var delegate : CollectionViewCellTap?

override func awakeFromNib() {
    super.awakeFromNib()

    //collectionView cell
    collectionView!.register(UINib(nibName: "CreateGroupCell", bundle: nil), forCellWithReuseIdentifier: "CreateGroupCell")
}

override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

}

 }

  //Collection View
 extension TableCollectionCell : UICollectionViewDataSource ,UICollectionViewDelegateFlowLayout
 {
    func collectionView(_ collectionView: UICollectionView,  numberOfItemsInSection section: Int) -> Int
{
    return 4
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CreateGroupCell", for: indexPath) as! CreateGroupCell

    cell.groupName.text = ""
    CreateCardView(viewCorner: cell.cardView)

    if(0 == indexPath.row)
    {
        //cell.btnDotted.tag = indexPath.row
        //cell.btnShare.tag = indexPath.row
        cell.btnDotted.setImage(UIImage(named: "Info"), for: UIControlState.normal)
        cell.btnShare.setImage(UIImage(named : "AddGroup"), for: UIControlState.normal)
    }

    else if(indexPath.row >= 1 && indexPath.row <= 3)
    {
        cell.btnDotted.isHidden = true
        cell.btnShare.isHidden = true
        cell.groupImage.image = UIImage(named: "group_dull_card.png")
    }

    else
    {

    }

    return cell
}


func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

    if ( 0 == indexPath.row) {

       delegate?.didTapCollectionViewCell(indexPath: indexPath.row)
    }
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

    return CGSize(width: 200, height: 150)
}
}

我是 iOS 的新人。

检查这个 -

我想你错过了这个

当您使用 dequeueReusableCell(withIdentifier:) 启动单元格对象时,您需要明确指定 CustomTableCell 的类型,否则它会认为 UITableViewCell 的对象没有 属性 delegate,所以只需在末尾添加as! TableCollectionCell,这样就可以访问class TableCollectionCell.[=17=的属性了]

var tableCollectionCell = tableView.dequeueReusableCell(withIdentifier: identifier) as? TableCollectionCell