Due to some purposes(like pull to refresh), I need a UICollectionView can bounce or scroll when there is no cells -- means numberOfItemsInSection:
return 0
I have my code like this:
...
UICollectionViewFlowLayout *flowLayout =[[UICollectionViewFlowLayout alloc] init];
flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
flowLayout.minimumInteritemSpacing = SPLIT_SPACE;
flowLayout.minimumLineSpacing = SPLIT_SPACE;
targetCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - TABBAR_HEIGHT)
collectionViewLayout:flowLayout];
[targetCollection registerNib:[UINib nibWithNibName:@"DashboardCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"DashboardCell"];
targetCollection.autoresizingMask = UIViewAutoresizingFlexibleHeight;
targetCollection.backgroundColor = [UIColor colorWithHex:@"#EAEAEA"];
targetCollection.contentInset = UIEdgeInsetsMake(0, 0, 20, 0);
targetCollection.alwaysBounceVertical = YES;
...
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section;
{
return 0;
}
However, when testing, this empty UICollectionView cannot bounce nor scroll. I suspect it is related to empty cell, but I do need to enable the bounce or scroll when no cell. This is similar to another of my problem:SVPullToRefresh cannot pull on an empty UICollectionView
collectionView.contentSize = CGRectMake(0,0,collectionView.bounds.size.width, collectionView.bounds.size.height + 10);
but no luck – Megaphone