我使用本教程Creating a Scrolling Filmstrip Within a UITableView在其单元格内创建了一个包含集合视图的表视图,但我希望实现一种横幅类型的功能,该功能集中了分页并自动滚动到每个单元格项目。我启用了页面滚动但没有工作。我该怎么做呢?我目前在表视图单元格中有一个UIView,用作集合视图的数据源。这是UIView子类的代码。
@interface ContainerCellView () <UICollectionViewDataSource, UICollectionViewDelegate>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (strong, nonatomic) NSArray *collectionData;
@end
@implementation ContainerCellView
#pragma mark - Getter/Setter ovverides
- (void)setCollectionData:(NSArray *)collectionData {
_collectionData = collectionData;
[_collectionView setContentOffset:CGPointZero animated:YES];
[_collectionView reloadData];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [self.collectionData count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ArticleCollectionViewCell";
BannersCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
NSDictionary *cellData = [self.collectionData objectAtIndex:indexPath.row];
cell.articleTitle.text = [cellData objectForKey:@"title"];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *cellData = [self.collectionData objectAtIndex:indexPath.row];
[[NSNotificationCenter defaultCenter] postNotificationName:@"didSelectItemFromCollectionView" object:cellData];
}
@end
答案 0 :(得分:0)
你可能正在寻找来自isPagingEnabled
的名为UIScrollView
的collectionView的属性,否则,你应该创建足够大的单元来实现这个非常好的效果。
但是,你可以在这里联系,如果你正在寻找按单元格分页click here
希望这可以帮到你