外出先で 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;
}
誰かが助けてくれれば、本当に感謝しています。前もって感謝します。