フレームワークを使用してフォト アルバムを作成できなかったので、コレクション ビューを使用して独自のフレームワークを作成しようとしていますが、最初は行き詰まりました。
私の目標は、Web サービスのすべての画像をコレクション ビューに表示することです。すべて表示されているため、次のステップは、誰かが任意のセルをタップしたときです。新しいビューで開いて、すべての間を移動することもできます。
ここに私が作成した基本的なコードがあります:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[collectionController reloadData];
tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:nil action:@selector(touched)];
tapGesture.numberOfTapsRequired = 1;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 6;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier = @"Cell";
CollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
[cell.imgCollection setImageWithURL:[NSURL URLWithString:@"http://sallescds.com.br/wp-content/uploads/2012/12/xepop-300x300.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
[cell.imgCollection addGestureRecognizer:tapGesture];
return cell;
}
-(void)touched:(UIGestureRecognizer *)tap{
NSLog(@"the touch happened");
}
みんなありがとう。