2013-04-04 31 views
-1

我在我的應用程序中使用PSUICollectionView,其中與圖像大拇指畫廊加載水平滾動視圖。 現在我需要兩個更多的collectionviews(畫廊)來顯示兩種其他類型的圖片。在ios中的同一屏幕上的多個collectionviews

任何人都可以請幫我嗎? 在此先感謝。

回答

1

簡單。像添加其他UIView一樣添加視圖。正確設置框架,他們應該工作。

爲每個人保留一個插座,然後你可以檢查他們中哪一個正在調用委託/數據源方法。

+0

我無需任何條件立即需要全部三個收集視圖。所以他們都必須立即調用委託/數據源方法。我如何實現? – Arun 2013-04-06 06:23:19

+0

在您的代理/數據源方法中,檢查查看哪個對象正在詢問並返回相應的信息。 – Undo 2013-04-06 13:26:39

+0

你可否請給我一個數據源/委託方法的例子多個集合視圖?我認爲沒有必要實施委託方法,因爲我只想顯示圖像並且不需要爲每個單元格執行操作。 – Arun 2013-04-08 06:35:29

4

我把它加在委託和數據源方法的一些代碼行如下工作 -

// setting tag 

    [self.imageCollection setTag:1]; 

    [self.finishImageCollection setTag:2]; 

    [self.prevImageCollection setTag:3]; 

編譯馬克 -

編譯標記集合視圖數據源

- (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]; 
    } 
} 
相關問題