当我点击UIViewController
内的项目时,我正在尝试打开新的UICollectionView
,但使用此代码我的应用程序崩溃,Xcode和模拟器重新启动,所以我甚至看不到它在哪里问题
import UIKit
class ViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
override func viewDidLoad() {
super.viewDidLoad()
collectionView?.register(CustomCell.self, forCellWithReuseIdentifier: "cellId")
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 5
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellId", for: indexPath) as! CustomCell
cell.imageViewGame.image = UIImage(named: imageArray[indexPath.row])
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: view.frame.width / 2, height: view.frame.width / 2)
}
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
performSegue(withIdentifier: "postController", sender: title[indexPath.row])
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "postController" {
let postController = segue.destination as! PostController
postController.title = sender as! String
}
}
}
有没有人从这段代码知道为什么我的应用程序崩溃了?如果这很重要,我就不会使用故事板。
答案 0 :(得分:0)