У меня есть контроллер (UICollectionView) в этом резюме я имею Еще один CVКак запустить эту функцию из другого контроллера
class HomeController: UICollectionViewController
func handleSearch(){
navigationController?.pushViewController(AlfavitController(), animated: true)}
collectionView?.register(MainScreenCell.self, forCellWithReuseIdentifier: "mainCell")
collectionView?.register(AlfavitCollectionCell.self, forCellWithReuseIdentifier: "alfavitCell")
collectionView?.register(AvtorCollectionCell.self, forCellWithReuseIdentifier: "avtorCell")
collectionView?.register(SaveCollectionCell.self, forCellWithReuseIdentifier: "saveCell")
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if indexPath.item == 0 {
return collectionView.dequeueReusableCell(withReuseIdentifier: "mainCell", for: indexPath)
}
if indexPath.item == 1 {
return collectionView.dequeueReusableCell(withReuseIdentifier: "alfavitCell", for: indexPath)
}
if indexPath.item == 2 {
return collectionView.dequeueReusableCell(withReuseIdentifier: "avtorCell", for: indexPath)
}
if indexPath.item == 3 {
return collectionView.dequeueReusableCell(withReuseIdentifier: "saveCell", for: indexPath)
}
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
return cell
В этом резюме я больше один CV
class AlfavitCollectionCell: UICollectionViewCell, UICollectionViewDelegateFlowLayout, UICollectionViewDelegate, UICollectionViewDataSource {
lazy var mainCollectionView : UICollectionView = {
let layout = UICollectionViewFlowLayout()
let mc = UICollectionView(frame: .zero, collectionViewLayout: layout)
mc.translatesAutoresizingMaskIntoConstraints = false
mc.delegate = self
mc.dataSource = self
mc.backgroundColor = UIColor(red: 98/255, green: 172/255, blue: 238/255, alpha: 0)
return mc
}()
var homeController:HomeController?
func setupCollection(){
addSubview(mainCollectionView)
mainCollectionView.backgroundColor = UIColor(red: 98/255, green: 172/255, blue: 238/255, alpha: 1)
mainCollectionView.register(AlfavitScreenCell.self, forCellWithReuseIdentifier: "cell")
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0":mainCollectionView]))
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-20-[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0":mainCollectionView]))
}
override init(frame: CGRect) {
super.init(frame: frame)
setupCollection()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! AlfavitScreenCell
cell.cellLabel.text = DataBase.arLetter[indexPath.item]
cell.backgroundColor = UIColor.white
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
homeController?.handleSearch()
}
Как я бегу homeController? .handleSearch() func in didSelectItemAt В отладчике homeController = nil? Где я должен делегировать или Somthing делать с HomeController
как установить делегат? Я не знаю, как это делается? Может быть, пример –
@maximrad проверить мои правки. Имеет ли это смысл? –