Это потому, что ваш класс eventsCustomCollectionCell является подклассом UICollectionViewCell, а не подклассом UIViewController.
func performSegue(withIdentifier identifier: String, sender: Any?)
- метод, доступный в UIViewController. Таким образом, для решения вы можете создать протокол в eventsCustomCollectionCell, который может иметь метод
func cellClicked(cell: eventsCustomCollectionCell)
и ваш FeedAndGroupsViewController может реализовать этот протокол и может вызывать performSegue.
Я написал скелетный код для вашего прецедента, вы можете обратиться к этому коду и начать работу.
class EventsCustomCollectionCell: UICollectionViewCell,UITableViewDelegate{
weak var delegate : EventsCustomCollectionCellDelegate?
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
delegate?.didClick(cell: self)
}
}
protocol EventsCustomCollectionCellDelegate : class{
func didClick(cell:EventsCustomCollectionCell)
}
class FeedAndGroupsViewController: UIViewController,EventsCustomCollectionCellDelegate,UICollectionViewDataSource{
var collectionView : UICollectionView!
var yourArrayForCollectionView = [String]()
func didClick(cell:EventsCustomCollectionCell){
if let index = collectionView.indexPath(for:cell){
let object = yourArrayForCollectionView[index.row]
performSegue(withIdentifier: "Your segue identifier", sender: object)
}
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Your cell reuse id", for: indexPath) as! EventsCustomCollectionCell
cell.delegate = self
return cell
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int{
return yourArrayForCollectionView.count
}
}
Надеюсь, это поможет.
Спасибо за вашу помощь! Я попробовал ваше решение, но, похоже, я не могу назвать делегата коллекцииViewCell в функции cellForItemAt. –
Вы должны вызвать метод делегата в файле didSelectRowAt UITableViewDelegate в вашем UICollectionViewCell. Я обновил свой код. –
Отлично! большое спасибо –