I got problem with moving to another ViewController
after click in the cell.
What I want to do:
- After click in the cell move to another
ViewController
, - Send
url
from picked cell to secondViewController
for downloading new data in it.
My CollectionView
look like that:
private func setupCollectionView() {
let layoutConfig = UICollectionLayoutListConfiguration(appearance: .insetGrouped)
let listLayout = UICollectionViewCompositionalLayout.list(using: layoutConfig)
collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: listLayout)
view.addSubview(collectionView)
collectionView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
collectionView.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor, constant: 0.0),
collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0.0),
collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0.0),
collectionView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0.0),
])
//MARK: - registration of cell with data from ViewModel
let cellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, PokemonResults> { (cell, indexPath, item) in
var content = cell.defaultContentConfiguration()
content.text = item.name
content.secondaryText = item.url
cell.contentConfiguration = content
}
dataSource = UICollectionViewDiffableDataSource<Section, PokemonResults>(collectionView: collectionView) {
(collectionView: UICollectionView, indexPath: IndexPath, identifier: PokemonResults) -> UICollectionViewCell? in
let cell = collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: identifier)
cell.accessories = [.disclosureIndicator()]
return cell
}
setupViewModel()
}
And my setupViewModel
like this:
private func setupViewModel() {
pokedexListVM.$pokemons
.receive(on: RunLoop.main)
.sink(receiveValue: { [weak self] _ in
self?.collectionView.reloadData()
}).store(in: &subscriptions)
self.snapshot = NSDiffableDataSourceSnapshot<Section, PokemonResults>()
self.snapshot.appendSections([.main])
self.snapshot.appendItems(self.pokedexListVM.pokemons, toSection: .main)
dataSource.apply(snapshot, animatingDifferences: false)
}
How to use delegate
in that kind of coding the CollectionView
?