作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
所以我有这个 Collection View ,其中的单元格包含一个编辑按钮,位于右上角。如何将 Action 连接到其中?
我尝试在 collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
中添加 cell.editbutton.addTarget
但它没有检测到 touchUpInside 事件.
最佳答案
在UICollectionViewCell中创建你的UIButton的outlet,写在
func collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
cell.button.tag = indexPath.row
cell.button.addTarget(self,
action: #selector(self.yourFunc(),
for: .touchUpInside)
}
func yourFunc(sender : UIButton){
print(sender.tag)
}
确保为按钮和 UICollectionViewCell 启用了 userInteraction。
关于swift - 如何在 Collection View 单元格中添加 uibutton 操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41456441/
我是一名优秀的程序员,十分优秀!