Вы не можете использовать performSegue()
в UITableViewCell
подклассе, потому что этот метод доступен только в UIViewController
s.
. Существует простое решение вашей проблемы - вы можете добавить «обратный вызов» вячейку и заполните этот обратный вызов в контроллере представления.
Ваша ячейка:
class ProductsTableViewCell: UITableViewCell {
var didSelectItemAction: ((IndexPath) -> Void)?
//...
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
didSelectItemAction?(indexPath)
}
}
Код в контроллере представления:
class ViewController: UITableViewController {
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "identifier", for: indexPath)
guard let productsCell = cell as? ProductsTableViewCell else {
return cell
}
productsCell.didSelectItemAction = { [weak self] indexPath in
self?.performSegue(withIdentifier: "yourID", sender: self)
}
return productsCell
}
}