navigate on click of collectionview cell inside tableview

后端 未结 4 937
悲&欢浪女
悲&欢浪女 2020-12-18 15:49

I have a tableview cell inside which i have added collectionview cell ( for horizontal scrolling).

Now i want to push to other navigation controller on pressing any

4条回答
  •  一个人的身影
    2020-12-18 16:22

    Make a protocol

    protocol collectionViewCellClicked{
        func cellClicked()
    }
    
    • Implement this protocol in main View Controller Your View Controller look like this

      class ViewController: UITableViewController, collectionViewCellClicked{ func cellClicked(){ // Your Code  }}
      
    • Your cellForRowAt delegate look like this

      override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: <#T##String#>, for: <#T##IndexPath#>) cell.delegate = self return cell }

    • In your Table View Cell Make a variable of type collectionViewCellClicked var delegate: collectionViewCellClicked?

      and in your didSelectItemAt delegate

      func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { delegate.cellClicked() }

提交回复
热议问题