Here is my code:
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
view.addSubview(tableView)
tableView.dataSource = self
Preformatted texttableView.delegate = self
}
}
extension SecondViewController: TableViewCellDelegate{
func tableViewCellDidTapItem(with viewModel: TileCollectionViewCellModel) {
let alert = UIAlertController(title: viewModel.name,
message: "",
preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Dismis",
style: .cancel,
handler: nil))
present(alert, animated: true)
}
}
protocol TableViewCellDelegate: AnyObject {
func tableViewCellDidTapItem(with viewModel: TileCollectionViewCellModel)
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
collectionView.deselectItem(at: indexPath, animated: true)
let viewModel = viewModels[indexPath.row]
delegatee?.tableViewCellDidTapItem(with: viewModel)
}