我试图打开新的UIViewController
当我点击UICollectionView
里面的一个项目,但是使用这个代码我的应用程序崩溃,Xcode和模拟器重新启动,所以我什至不能看到问题出在哪里。快速打开新的UIViewController
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
}
}
}
有没有人知道从这段代码为什么我的应用程序崩溃?如果重要,我不使用故事板。
你也必须写,你得到错误信息。我们不是预兆。 –
1.调试日志说什么? 2. postController标识符是否存在? – carlos21
我看不到错误消息,我的Xcode每次崩溃。 – user3593157