gpt4 book ai didi

ios - didSelectItemAt()未加载我的viewController

转载 作者:行者123 更新时间:2023-12-01 19:43:50 25 4
gpt4 key购买 nike

第一个viewController

   import UIKit

class photosCollectionViewController: UIViewController,UICollectionViewDelegate,UICollectionViewDataSource {

@IBOutlet weak var photoCollectionView: UICollectionView!

override func viewDidLoad() {
super.viewDidLoad()
photoCollectionView.delegate = self
photoCollectionView.dataSource = self

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}

var photosArray = PhotoClass(Name:["Dog","Cat","Lion","Tiger"])
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return photosArray.Name.count

}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let photocell = photoCollectionView.dequeueReusableCell(withReuseIdentifier: "photosCell", for: indexPath) as! photoscollectionCell
//photocell.backgroundColor = UIColor.blue
photocell.cellImage.image = UIImage(named: photosArray.Name[indexPath.row])
photocell.cellLabel.text = photosArray.Name[indexPath.row]

return photocell
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("Something")
let vc = self.storyboard?.instantiateViewController(withIdentifier: "photosDetails") as! detailsCollectionViewController
// vc.descriptionLabel.text = "Animals"

}
}

didSelectItemAt()不会加载我的detailsCollectionViewController,但是当我选择单元格时,它正在调用.so,我在哪里做错了?

最佳答案

如果要推送,可以编写以下代码:

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("Something")
let vc = self.storyboard?.instantiateViewController(withIdentifier: "photosDetails") as! detailsCollectionViewController
// vc.descriptionLabel.text = "Animals"
self.navigationController?.pushViewController(vc, animated: true)
}

可能对您有帮助。谢谢

关于ios - didSelectItemAt()未加载我的viewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51400156/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com