简体   繁体   English

以编程方式创建的按钮不会收到事件内部的修饰…UICollectionViewCell

[英]Buttons created programmatically doesn't receive touch up inside events… UICollectionViewCell

I'm creating Collection View Cells programmatically using Facade framework to position it right. 我正在使用Facade框架以编程方式创建Collection View Cells,以使其正确定位。 Unfortunately buttons inside cells doesn't react to touches. 不幸的是,单元格内的按钮对触摸没有反应。 Collection View is created using storyboard. 集合视图是使用情节提要创建的。 CollectionViewCell appearance loading: 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;

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. 阿德里安

Ok I just figured it out... I had image as background (UIButton was subview) and UIImageView has userInteractionEnabled disabled as default. 好的,我刚刚弄清楚了...我将图像作为背景(UIButton是子视图),UIImageView将userInteractionEnabled禁用为默认值。 Setting this property to YES, fixed issue. 将此属性设置为“是”,已解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 自定义UIView不接收触摸事件 - Custom UIView doesn't receive touch events 从笔尖加载的视图不接收触摸事件 - A view loaded from the nib doesn't receive touch events 无法接收以实用方式创建的 UIButton 的触摸事件 - unable receive touch events of UIButton created pragrammatically 添加多个按钮+以编程方式在UICollectionViewCell SWIFT中接收touchUpInside事件 - Adding multiple buttons + receiving touchUpInside event inside UICollectionViewCell SWIFT programmatically 将触摸事件传递给UICollectionViewCell内容? - Pass touch events to a UICollectionViewCell contents? UIImageView animation 内部 UICollectionViewCell 不工作 - UIImageView animation inside UICollectionViewCell doesn't work 在另一个视图上设置动画后,动画视图不接收触摸事件 - Animated view doesn't receive touch events after animating over another view 当按钮在内部触摸时,如何从Superview中删除以编程方式创建的子视图? - How to remove a programmatically created subview from Superview when button touch up inside? 以编程方式添加约束以禁用内部修饰 - Adding constraints programmatically disabled the touch up inside 获取MKMapView以响应内部事件的补全 - Get MKMapView to respond to touch up inside events
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM