ios中同一屏幕上的多个集合视图

时间:2013-04-04 14:09:43

标签: iphone ios objective-c uicollectionview

我在我的应用程序中使用PSUICollectionView,其中带有图像拇指的图库加载了水平滚动视图。 现在我还需要两个集合视图(画廊)来显示另外两种类型的图片。

任何人都可以帮帮我吗? 提前谢谢。

2 个答案:

答案 0 :(得分:4)

我通过在委托和数据源方法中添加一些代码行来实现它,如下所示 -

    // setting tag

   [self.imageCollection setTag:1];

   [self.finishImageCollection setTag:2];

   [self.prevImageCollection setTag:3];

pragma mark -

pragma mark集合查看数据源

 - (NSString *)formatIndexPath:(NSIndexPath *)indexPath {
       return [NSString stringWithFormat:@"%ld", (long)indexPath.row+1];
   }

  // Populating cells 
  - (PSUICollectionViewCell *)collectionView:(PSUICollectionView *)collectionView        cellForItemAtIndexPath:(NSIndexPath *)indexPath {
   ImageGridCell *cell = [collectionView    dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
   if(collectionView.tag==1){
     cell.statusImage.image= [UIImage imageNamed:@"checked.png"];
     cell.imageThumb.image = [self.startImages objectAtIndex:indexPath.row];
   }

   if(collectionView.tag==2){
    cell.statusImage.image= [UIImage imageNamed:@"checked.png"];
    cell.imageThumb.image = [self.finishImages objectAtIndex:indexPath.row];
   }

   if(collectionView.tag==3){
    cell.statusImage.image= [UIImage imageNamed:@"checked.png"];
    cell.imageThumb.image = [self.prevImages objectAtIndex:indexPath.row];
   }
   return cell;
  }

   - (NSInteger)collectionView:(PSUICollectionView *)collectionView    numberOfItemsInSection:(NSInteger)section {
   int imgCount;
   if(collectionView.tag==1)
   {
    [self loadStartPictures];
    imgCount=self.startImages.count;
   }
   if(collectionView.tag==2)
   {
    [self loadFinishPictures];
    imgCount=[self.finishImages count];
   }
   if(collectionView.tag==3)
   {
    [self loadSupervisorPictures];
    imgCount=[self.prevImages count];
   }
   return imgCount;
  }


  #pragma mark -
  #pragma mark Collection View Delegate

  - (void)collectionView:(PSTCollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  {
   self.allImages=[[NSMutableArray alloc]init];
   UIImage *imageAtIndexPath;
   NSLog(@"Delegate cell %@ : SELECTED", [self formatIndexPath:indexPath]);
   ImageGridCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
   cell.label.backgroundColor=[UIColor underPageBackgroundColor];

   if(collectionView.tag==1){
    imageAtIndexPath=[self.startImages objectAtIndex:indexPath.row];
    }
  if(collectionView.tag==2){
    imageAtIndexPath=[self.finishImages objectAtIndex:indexPath.row];
    }
  if(collectionView.tag==3){
    imageAtIndexPath=[self.supervisorImages objectAtIndex:indexPath.row];
    }
 }

答案 1 :(得分:1)

<强>简单即可。只需像任何其他UIView一样添加视图。正确设置框架,它们应该可以正常工作。

为每个插槽保留一个插座,然后您可以检查其中哪一个正在调用委托/数据源方法。