UICollectionViewController Programmabsturz mit Nicht-Null-Layoutparameterfehler

Ich erschaffe eineUICollectionViewController programmatisch. Nein, ich möchte IB und Storyboards nicht wie jedes andere Tutorial verwenden. Ich möchte nur einfachen Code verwenden.

Hier ist was ich in meinem habeviewDidLoad:

// UICollectionView
    UICollectionViewFlowLayout *aFlowLayout = [[UICollectionViewFlowLayout alloc] init];
    [aFlowLayout setItemSize:CGSizeMake(200, 140)];
    [aFlowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    self.collectionView = [[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:aFlowLayout];
    [self.collectionView setDelegate:self];
    [self.collectionView setDataSource:self];
    self.collectionView.backgroundColor = [UIColor clearColor];
    [self.collectionView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth];
    [self.collectionView registerClass:[PUCImageGridCell class] forCellWithReuseIdentifier:CollectionViewCellIdentifier];

Ich habe die erforderlichen Delegate-Methoden implementiert und erhalte weiterhin den folgenden Fehler:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'UICollectionView must be initialized with a non-nil layout parameter'

Antworten auf die Frage(1)

Ihre Antwort auf die Frage