![](/img/trans.png)
[英]cellForItemAtIndexPath not called with custom UICollectionViewLayout
[英]cellForItemAtIndexPath: is not called when using custom UICollectionViewLayout subclass
使用我的自定義UICollectionViewLayout
子類時,不調用cellForItemAtIndexPath:
我使用斷點和調試輸出檢查)。 這是我使用自定義布局的方式:
- (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"];
}
但是,當我將上面的代碼更改為使用UICollectionViewFlowLayout
而不是我的自定義子類時,將調用cellForItemAtIndexPath:
.
難道我的自定義布局子類中的某些代碼會阻止cellForItemAtIndexPath
嗎?
例如,如果布局沒有為集合視圖返回任何大小,或者布局對象的任何大小,則永遠不會創建單元格。 此外,布局對象中的幀必須位於集合視圖的可見區域內。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.