I want to show/hide collection view inside the table view's check button selection
I am trying to use delegate and protocol for that.
1.I create protocol in table view cell class
protocol CustomCellDelegate{
func selectCollectionView(cell: InsideTableViewCell)
}
Note:I create selectCollectionView function inside the main view controller
2.declare delegate variable inside the main view class
var delegate: CustomCellDelegate?
3.Confirm to the CustomCellDelegate in the main class
class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource,CustomCellDelegate
4.Use selector function to provide table view button inside the cellForRowAtIndexPath function
cell.checkButton.addTarget(self, action: #selector(self.selectCheck(_:)), for: .touchUpInside)
cell.delegate = self
5.Selector function
@objc func selectCheck(_ sender: UIButton) {
if sender.isSelected {
sender.isSelected = false
print("Check 1")
delegate?.selectCollectionView(cell: InsideTableViewCell)
} else{
print("Check 2")
sender.isSelected = true
}
}
6.selectCollectionView function
func selectCollectionView(cell: InsideTableViewCell) {
cell.clCollectionView.isHidden = true
}
I am trying to call selectCollectionView function inside the selectCheck button
but I get error like "Cannot convert value of type 'InsideTableViewCell.Type' to expected argument type 'InsideTableViewCell'"
If I do mistake please let me know.
I referred this link:How to access the content of a custom cell in swift using button tag?
And Screenshot of output: