2013-04-02 18 views
8

Program aracılığıyla bir UICollectionViewController oluşturuyorum. Hayır, orada her öğretici gibi IB ve Storyboard kullanmak istemiyorum. Sadece düz kod kullanmak istiyorum. İşte UICollectionViewController Programsal olarak sıfır olmayan düzen parametre hatasıyla kilitleniyor

ben ne var benim viewDidLoad: Ben gerekli temsilci yöntemleri uygulamış ve hala bu hatayı alıyorum

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

:

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

cevap

10

Bu ben UICollectionViewController başlatmak için kullandığınız :

- (id)initWithCollectionViewLayout:(UICollectionViewLayout *)layout 

Sen instantia gerekmez collectionView kontrolör sizin için yapacak. Bu çağrıldıktan sonra çerçeveyi ayarlayın veya içeri çerçevesini geçersiz ve ayarlayabilirsiniz:

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

Ben autolayout kısıtlamaları kullanmayı tercih ediyorum.

İlgili konular