1

外出先で 2 つの個別の画像ギャラリーを必要とするアプリを使用しています。UICollectionView を使用して、この最初の 1 つを行いました。UICollectionView が完全に機能するようにすべてを設定しました。各画像をクリックしてフルスクリーンで表示できるようにしたいだけです。また、別のページで別の画像を使用して 2 番目の UICollectionView を作成する方法も知りたいです。2 番目の UICollectionView を作成し、それに myCollectionView2 という名前を付けて、画像配列と同じように簡単ですか?

これは、最初のコレクション用に現在持っているコードです。

#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;
}

誰かが助けてくれれば、本当に感謝しています。前もって感謝します。

4

2 に答える 2

0

UICollectionView 内の選択に応答するには、UICollectionViewController が既に準拠している UICollectionViewDelegate プロトコルに少なくとも 1 つのメソッドを実装する必要があります。

皮切りに:

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

このメソッドにブレークポイントを配置すると、コレクション ビューの要素に触れるたびに、このメソッドが起動され、indexPath が含まれていることがわかります。

あなたが説明する一般的なアプローチには、そのパスによって参照される画像を取得し、それをより大きな UIImageView 内に配置し、そのビューを階層に追加することが含まれます。

于 2013-11-14T13:07:14.940 に答える
0

2 つ以上の UICollectionview を作成しないでください。できることは、2 番目のページが表示されるときに、Collectionview を空の配列でリロードすることです。ページが表示されたら、新しい画像セットを Collectionview にロードします。その逆も同様です。

于 2013-11-14T13:17:21.130 に答える