У меня есть UICollectionView, отображающий миниатюры изображений. Каждое представление изображения в сетке имеет жест касания. Мой вопрос в том, как я могу получить именно ту ячейку, которая была использована? Например. «Простучали по индексу № 43».
Дополнительные комментарии
- Тап-жест создавался программно, раскадровка не использовалась.
- В этом проекте у меня включены ARC и Story Board.
Вот самое близкое, что я пришел:
UICollectionViewController
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
int row = [indexPath row];
CollectionViewCell *Cell = [collectionView
dequeueReusableCellWithReuseIdentifier:@"Cell"
forIndexPath:indexPath];
// Enable tap gesture on each ImageView
[Cell.ImageView setUserInteractionEnabled:YES];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture)];
[tapGesture setNumberOfTouchesRequired:1];
[tapGesture setNumberOfTapsRequired:1];
[tapGesture setDelegate:self];
[Cell.ImageView addGestureRecognizer:tapGesture];
Cell.ImageView.tag = row; // This tags correctly
}
- (void)tapShowImage // Also, for some reason,
// - (void)handleTapGesture:(UITapGestureRecognizer *)sender
// doesn't work. I get an invalid selector error.
{
NSLog(@"%i", Cell.ImageView.tag);
// Doesn't work because I can't call Cell.ImageView.tag here.
// Might be because I"m using SDWebImage to load the image
// into the ImageView above but not sure.
}
UITapGestureRecognizerселектор должен бытьhandleTapGesture:, а не толькоhandleTapGesture. Обратите внимание на использование:. Это нужно для того, чтобы показать, что у вас есть аргумент в объявлении метода, то естьsender. - person esh   schedule 07.08.2013