Tôi đang tạo một UICollectionViewController
theo chương trình. Không, tôi không muốn sử dụng IB và Storyboards như mọi hướng dẫn trên mạng. Tôi chỉ muốn sử dụng mã đơn giản.UICollectionViewController Lập trình bị lỗi với lỗi tham số bố cục phi nil
Đây là những gì tôi có trong tôi 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];
tôi đã thực hiện các phương pháp đại biểu cần thiết và tôi vẫn nhận được lỗi này:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'UICollectionView must be initialized with a non-nil layout parameter'