我正在使用带有自定义单元格的 Collection View 。我不知道为什么,但我的单元格停止工作(它们不再调用 didSelect)。
基本上,这是一个简单的单元格,我只是在其上面放置了一个 View (addSubview)。 该 View 包含两个 imageView 和两个标签。
我注意到,当我不添加此 View 时,他们会调用 didSelect。没有办法在 UITableViewCell 上添加 View 吗?
这是我用来添加 View 的代码:
- (void)setCellWithMediaView:(TVNCategoryWideAndTallMediaView *)mediaView {
if (self.contentView.subviews.count > 0) {
[[self.contentView.subviews lastObject] removeFromSuperview];
}
self.categoryWideAndTallMediaView = [[TVNCategoryWideAndTallMediaView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
self.categoryWideAndTallMediaView = mediaView;
[self.contentView addSubview:self.categoryWideAndTallMediaView];
self.isMediaSet = YES;
}
最佳答案
您可以将该 View 和 subview 的 userInteractionEnabled
属性设置为 NO
。
self.categoryWideAndTallMediaView.userInteractionEnabled = NO;
关于xcode - 添加 subview 后 UICollectionViewCell 不可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18735207/