2013-11-14 30 views
1

我有一個應用程序需要兩個獨立的圖像庫。我已經使用UICollectionView完成了第一個。我已經設置了一切,以便UICollectionView完美工作,我只是希望能夠點擊每個圖像以全屏查看它們。我還想知道如何在不同圖像的不同頁面上構建第二個UICollectionView。是否就像製作第二個UICollectionView並將其命名爲myCollectionView2一樣簡單,並且與Image Arrays一樣?UICollectionView中的圖像點擊進入全屏

這是我現在有第一個集合代碼:

#import "CollectionViewController.h" 
#import "CustomCell.h" 

@interface CollectionViewController() 
{ 
    NSArray *ArrayOfImages; 
} 

@end 

@implementation CollectionViewController 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    [[self myCollectionView1]setDataSource:self]; 
    [[self myCollectionView1]setDelegate:self]; 

    ArrayOfImages = [[NSArray alloc] initWithObjects:@"MacLeodsAccessories.png", @"MacleodsBag.png", @"MacleodsBag1.png", @"MacleodsBag2.png", @"MacleodsCollar.png", @"MacleodsCushions.png", @"MacleodsPurse.png", @"MacleodsTeaAndCoffee.png", nil]; 
} 

//datasource and delegate method 
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView 
{ 
    return 1; 
} 

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 
{ 
    return [ArrayOfImages count]; 
} 

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    CustomCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath]; 

    [[cell myImage]setImage: [UIImage imageNamed:[ArrayOfImages objectAtIndex:indexPath.item]]]; 

這可能是編碼都是錯誤的,並很可能是多餘的,但還是可能正是我需要的,我只是不知道如何糾正它,以及我在這裏放置什麼,這將使這項工作。

[[cell myImage]setGestureRecognizers:[ArrayOfImages objectAtIndex:indexPath.item]]; 

    return cell; 
} 

如果有人可以幫忙,我會很感激。 在此先感謝。

回答

0

要響應UICollectionView中的選擇,您必須使用您的UICollectionViewController已符合的implement at least one method in the UICollectionViewDelegate Protocol

開始:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 

發生在這個方法中設置斷點,你會看到你觸摸你的收藏視圖的元素每次,這種方法被解僱,包括indexPath你。

對於您所描述的常見方法,將涉及獲取該路徑引用的圖像,將其放置在較大的UIImageView中並將該視圖添加到層​​次結構中。

0

請勿創建兩個或更多UICollectionView。你可以做什麼,當第二頁是可見的重新加載CollectionView與空數組。一旦你的頁面可見,將新的一組圖像加載到Collectionview中,反之亦然。