0

I'm creating Collection View Cells programmatically using Facade framework to position it right. Unfortunately buttons inside cells doesn't react to touches. Collection View is created using storyboard. CollectionViewCell appearance loading:

_likesButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_likesButton setBackgroundColor:[UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:0.10]];
_likesButton.contentEdgeInsets = UIEdgeInsetsMake(5, 8, 5, 8);
_likesButton.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
_likesButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
[_likesButton setAttributedTitle:[self attributedSpacedStringFromString:@"+10039" withColor:[UIColor flatWhiteColor] withFont:[UIFont fontWithName:@"OpenSans-Bold" size:12]] forState:UIControlStateNormal];
_likesButton.layer.cornerRadius = 12;
[_likesButton sizeToFit];
_likesButton.userInteractionEnabled = YES;

In Collection View:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];

cell.likesButton.tag = indexPath.row;
[[cell likesButton] addTarget:self action:@selector(showAlert:) forControlEvents:UIControlEventTouchUpInside];

return cell;
}

What I'm doing wrong? Best regards,

Adrian.

Adish
  • 25
  • 8

1 Answers1

0

Ok I just figured it out... I had image as background (UIButton was subview) and UIImageView has userInteractionEnabled disabled as default. Setting this property to YES, fixed issue.

Adish
  • 25
  • 8