jerrygdm
jerrygdm

Reputation: 450

UICollectionViewCell subview receive tap insted

I have a UICollectionViewCell with some my content on it as image, labels, views.

I would like to obtain this behavior (like an opposite behavior of a normal cell):

If I try to install a UITapRecognizer:

    // Create gesture recognizer
UITapGestureRecognizer *oneTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onShadowLayerPressed)];

// Set required taps and number of touches
[oneTap setNumberOfTapsRequired:1];
[oneTap setNumberOfTouchesRequired:1];

// Add the gesture to the view
[self.shadowView addGestureRecognizer:oneTap];

and after the method

 - (void)onShadowLayerPressed
{
    [super setSelected:YES];
    [self setSelected:YES];
}

The tap is received from the self.shadowView but it doesn't send to the cell....

How can I solve this issue?

Thanks

Upvotes: 1

Views: 643

Answers (1)

mprivat
mprivat

Reputation: 21902

You are using @property (nonatomic, getter=isSelected) BOOL selected and according to the docs,

You typically do not set the value of this property directly. Changing the value of this property programmatically does not change the appearance of the cell. The preferred way to select the cell and highlight it is to use the selection methods of the collection view object.

So you are supposed to use:

- (void)selectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UICollectionViewScrollPosition)scrollPosition

Which is documented here.

Upvotes: 2

Related Questions