2013-04-10 81 views
3

我一直在做很多的阅读,看着应用程序样本,我仍然不确定如何实现一个集合视图,推到与分页的详细视图?收藏查看和详细信息查看分页

我能够得到一个集合视图推到一个静态的详细视图(不幸的是没有标题),我可以得到分页工作没有集合视图,但不是两个在一起!?我还需要考虑一个题目,这是一个重要的部分。

请有人可以帮我这个,我可以去疯狂很快:)

许多在此先感谢!

回答

2

只需按另一个采集视图控制器,使用流布局,水平滚动方向,启用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; 
} 

P.S.要设置内容偏移使用[self.collectionView setContentOffset:CGPointMake(40, 0)];

+0

对不起,我是新来的所有这些,我该怎么做? – David 2013-04-25 16:11:30

+0

我刚刚编辑了我的帖子。希望这可以帮助 – 2013-04-26 09:23:46

相关问题