[英]collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath is not executed
Here is my image of collectionViewCell . 这是我的collectionViewCell图像。
I have collectionView
inside tableViewCell
and I have a button inside collectionViewCell
which is working perfectly as my wish. 我曾经collectionView
内tableViewCell
和我都有一个内置按钮collectionViewCell
这是工作完美我的心愿。 But What is troubling me is the function didSelectItemAt
is not being called . 但是令我困扰的是未调用函数didSelectItemAt
。
I tried with 我尝试过
mycollectionview.isUserInteractionEnabled = true
mycollectionview.allowsSelection = true
but still not working . 但仍然无法正常工作。 Is the button inside collectionViewCell
is the cause behind it as I read somewhere . 我在某处阅读时, collectionViewCell
内部的按钮是否是其背后的原因。 If its is so how can I fix the issue . 如果是这样,我该如何解决此问题。
Please confirm that you have set the delegate for the UICollectionView
to your ViewController not the TableViewCell
. 请确认已将UICollectionView
的委托设置为ViewController而不是TableViewCell
。 If you have set the Delegate to UITableViewCell
, then your didSelectItemAt
will be called inside the TableViewCell's
class 如果已将Delegate设置为UITableViewCell
,则您的didSelectItemAt
将在TableViewCell's
类中调用
try this code in swift 4 快速尝试此代码4
cell.btnCart.addTarget(self, action: #selector(btnCartAction), for: .touchUpInside)
and handle the action 并处理行动
@objc func btnCartAction(sender:UIButton) {
//write your code here
}
Check your all views which are placed on cell.If they have user interaction enabled and if user interaction enabled then what is the size of that item. 检查所有放置在单元格上的视图。如果它们启用了用户交互,并且如果启用了用户交互,那么该项目的大小是多少。 It looks like some view is covering the whole cell that's why did select item does not get called. 看起来有些视图覆盖了整个单元格,这就是为什么选择项没有被调用的原因。
请检查您的Button大小,tableView选择(单选或多次),检查tableView用户是否启用了交互,还检查数据源或委托是否已连接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.