CellForItemAtIndexPath: not called when using a custom subclass of UICollectionViewLayout

When using my custom subclass, UICollectionViewLayout cellForItemAtIndexPath: not called (I checked the use of breakpoints and debug output). This is how I use custom layout:

 - (void)viewDidLoad { [super viewDidLoad]; DMSGridLayout* gridLayout = [[DMSGridLayout alloc] init]; // UICollectionViewFlowLayout* flow = [[UICollectionViewFlowLayout alloc] init]; // [flow setItemSize:CGSizeMake(150, 150)]; UICollectionView *collection = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:gridLayout]; collection.delegate = self; collection.dataSource = self; self.collectionView = collection; [self.view addSubview:self.collectionView]; [self.collectionView registerClass:[DMSGridCell class] forCellWithReuseIdentifier:@"CollectionCell"]; } 

But when I change the above code to use UICollectionViewFlowLayout instead of my custom subclass, cellForItemAtIndexPath: is cellForItemAtIndexPath: .

Could it be that some code from my subclass of custom layout prevents calling cellForItemAtIndexPath ?

+6
source share
1 answer

If the layout does not return any size for the collection view, for example, or any size for layout objects, then the cell will never be created. In addition, the frames in the layout objects must be within the visible area of ​​the collection view.

+5
source

Source: https://habr.com/ru/post/955422/


All Articles