【发布时间】:2013-04-10 16:09:43
【问题描述】:
我一直在阅读和查看应用程序示例,但仍然不确定如何实现通过分页推送到详细视图的集合视图?
我可以让一个集合视图推送到一个静态详细视图(不幸的是没有标题),并且我可以在没有集合视图的情况下进行分页工作,但不能同时使用!?我还需要考虑一个标题,这是一个重要的部分。
请有人帮我解决这个问题,因为我可能很快就会发疯:)
非常感谢!
【问题讨论】:
标签: ios xcode uicollectionview
我一直在阅读和查看应用程序示例,但仍然不确定如何实现通过分页推送到详细视图的集合视图?
我可以让一个集合视图推送到一个静态详细视图(不幸的是没有标题),并且我可以在没有集合视图的情况下进行分页工作,但不能同时使用!?我还需要考虑一个标题,这是一个重要的部分。
请有人帮我解决这个问题,因为我可能很快就会发疯:)
非常感谢!
【问题讨论】:
标签: ios xcode uicollectionview
只需推送另一个具有流布局、水平滚动方向、启用paging 属性并将布局的itemSize 属性设置为全屏的集合视图控制器。在将此控制器的设置内容偏移量推送到所选图像上之前。试试下面的代码。您应该调用initWithCollectionViewLayout 来初始化您的收藏视图。
-(id)initWithCollectionViewLayout:(UICollectionViewLayout *)layout {
if (self = [super initWithCollectionViewLayout:layout]) {
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"Cell"];
UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout;
layout.itemSize = self.collectionView.bounds.size;
layout.minimumLineSpacing = 0;
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
self.collectionView.pagingEnabled = YES;
// In order to see cells you can declare something like colors array in .h
self.colors = @[[UIColor redColor], [UIColor greenColor], [UIColor blueColor]];
}
return self;
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.shopNames.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
[cell.contentView setBackgroundColor:self.colors[indexPath.item]];
return cell;
}
附:设置内容偏移使用[self.collectionView setContentOffset:CGPointMake(40, 0)];
【讨论】: