2013-04-02 8 views
8

Programowo programuję UICollectionViewController. Nie, nie chcę używać IB i Storyboardów jak każdy tutorial tam. Po prostu chcę użyć zwykłego kodu.UICollectionViewController Programowe zawieszenie z niezerowym błędzie parametru układu

Oto co mam w viewDidLoad:

// 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]; 

I wprowadziły wymaganych metod delegata i wciąż otrzymuję ten błąd:

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

Odpowiedz

10

To co mam użyć, aby zainicjować UICollectionViewController :

- (id)initWithCollectionViewLayout:(UICollectionViewLayout *)layout 

Nie potrzebujesz aplikacji instantia te kolekcjeZobacz sterownik zrobi to za Ciebie. Ustaw kadr po wywołaniu tego czy można zastąpić i ustawić ramkę wewnątrz:

- (id)initWithCollectionViewLayout:(UICollectionViewLayout *)layout{ 
    self = [super initWithCollectionViewLayout:layout]; 
    if (self) { 
     // additional setup here if required. 
    } 
    return self; 
} 

wolę używać ograniczeń autolayout.

Powiązane problemy