0

我正在使用 Facade 框架以编程方式创建集合视图单元以正确定位它。不幸的是,单元格内的按钮对触摸没有反应。集合视图是使用情节提要创建的。CollectionViewCell 外观加载:

_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;

在集合视图中:

- (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;
}

我做错了什么?此致,

阿德里安。

4

1 回答 1

0

好的,我只是想通了...我将图像作为背景(UIButton 是子视图),并且 UIImageView默认禁用了userInteractionEnabled 。将此属性设置为 YES,已解决问题。

于 2015-09-08T09:23:53.150 回答