-1

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

谁能帮帮我??提前致谢。

4

2 回答 2

4

我通过在委托和数据源方法中添加一些代码行来使其工作,如下所示 -

    // setting tag
    
   [self.imageCollection setTag:1];
    
   [self.finishImageCollection setTag:2];
    
   [self.prevImageCollection setTag:3];
    

语用标记 -

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];
    }
 }
于 2013-04-10T06:24:43.720 回答
1

简单。只需像添加任何其他 UIView 一样添加视图。正确设置他们的框架,他们应该工作。

为他们每个人保留一个出口,然后您可以检查他们中的哪一个正在调用委托/数据源方法。

于 2013-04-04T14:20:17.830 回答