6

使用我的自定义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被调用?

4

1 回答 1

5

例如,如果布局没有为集合视图返回任何大小,或者没有为布局对象返回任何大小,则永远不会创建单元格。此外,布局对象中的框架必须在集合视图的可见区域内。

于 2013-10-07T18:34:15.547 回答