gpt4 book ai didi

ios - 将 didSelectItem 用于编程的 UICollectionViewCell

转载 作者:行者123 更新时间:2023-11-28 19:27:37 25 4
gpt4 key购买 nike

我已经编写了一个 UICollectionView,当选择单元格时,我希望它转到另一个 View Controller 。我收到错误消息

Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value.

    override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let vc = storyboard?.instantiateViewController(withIdentifier: "twoVC") as? twoVC

self.navigationController?.pushViewController(vc!, animated: true)
//Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
}

}

class twoVC : UIViewController {
@IBOutlet var label : UILabel!

@IBOutlet var photo : UIImageView!

}

最佳答案

你正在强制展开 vc 所以它很可能是 nil 这意味着 "twoVC" 可能不是该 View 的标识符 Storyboard中的 Controller 。在你的 Storyboard中仔细检查:

enter image description here

关于ios - 将 didSelectItem 用于编程的 UICollectionViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50531680/

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