在这里,您将didSelectItemAtIndexPath
在CategoryRow
类上的委托方法上单击单元格,然后可以在其中触发委托以在ViewController
内部进行调用:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! CategoryRow
cell.delegate = self
return cell
}
:
protocol CategoryRowDelegate:class {
func cellTapped()
}
:
class CategoryRow : UITableViewCell {
weak var delegate:CategoryRowDelegate?
@IBOutlet weak var collectionView: UICollectionView!
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if delegate!= nil {
delegate?.cellTapped()
}
}
func cellTapped(){
//code for navigation
}