xcode - 添加 subview 后 UICollectionViewCell 不可点击

标签 xcode uicollectionview

我正在使用带有自定义单元格的 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/

相关文章:

c++ - 在 Xcode 项目中使用动态库 (DevIL/OpenIL)

swift - UITableView 中的 UICollectionView 由于 view.addGestureRecognizer() 未检测到点击

ios - 无法在 Xcode 版本 9.0.1 上模拟位置 (9A1004)

ios - 应用程序在 iCloud 中存储数据

swift - 使用 UserDefaults 更新数据模型

ios - 为什么我们需要通过 dequeueReusableCell func 获得的 upcasting cell?

ios - 在 iphone 中更改自定义集合单元格 subview 的框架

ios - 将数组中的图像嵌入到 Collection View 的单元格中

ios - 在终端上使用 xcodebuild 命令导出失败

ios - NSBatchUpdateRequest 在 Swift 中引发错误