cellview java_UITableViewCell里面的UICollectionViewCell没有响应动作

我正在开发一个项目,其中在UITableView内部的UITableViewCell内部有一个UICollectionView . 我使用XIB作为我的UICollectionViewCell,它包含一个ImageView,另一个XIB用于我的UITableViewCell,它包含一个UICollectionView . 我已设法显示所需的东西,但是,我的自定义集合视图单元格没有响应任何触摸事件 . 经过一番研究,我尝试过:

在界面生成器中的UITableView和UITableViewCell中以编程方式关闭"User Interaction Enabled",同时在UICollectionView和UICollectionViewCell中打开"User Interaction Enabled"

在UITableViewCell中设置UICollectionView的委托,我的自定义UITableViewCell类实现UICollectionViewDelegate和UICollectionViewDataSource

collectionView.delegate = self

collectionView.dataSource = self

使用UICollectionView的委托方法

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

// my implementation here

}

为cellForItemItemAt中的每个单元格添加自定义UITapGestureRecognizer

let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(MyCustomTableViewCell.cellTapped))

tapRecognizer.numberOfTapsRequired = 1

cell.addGestureRecognizer(tapRecognizer)

使用UITableViewCell,UICollectionView和UICollectionViewCell的自定义实现,覆盖hitTest函数

override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {

if let hitView = super.hitTest(point, with: event) {

if hitView is MyCustomCollectionViewCell {

print("hitTest - MyCustomCollectionViewCell")

return hitView

} else {

return nil

}

} else {

return nil

}

}

这是我的自定义TableViewCell XIB的屏幕截图:

f7b789e0-3d39-44f5-b2f4-ab5850062c96.png

任何帮助表示赞赏 . 谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值