Ich versuche, UIViewController
zu öffnen, wenn ich auf einen Artikel innerhalb UICollectionView
klicke, aber mit diesem Code stürzt meine App und Xcode und Simulator neu gestartet, so dass ich nicht einmal sehen kann, wo das Problem ist.Schnell öffnen neuer 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
}
}
}
Kennt jemand aus diesem Code, warum meine App abstürzt? Wenn es wichtig ist, verwende ich kein Storyboard.
Sie haben auch Fehlermeldung schreiben, die Sie bekommen. Wir sind kein Augur. –
1. Was sagt das Debugprotokoll? 2. PostController Identifier existiert? – carlos21
Ich kann keine Fehlermeldung sehen, mein Xcode stürzt jedes Mal ab. – user3593157