我有这个层次结构。
UITableView-> UITableViewCell-> UICollectionView-> UICollectionViewCell-> UIButton。 如何使用swift4处理uibutton上的点击事件?
答案 0 :(得分:0)
在cellForRowAt
内部做
let cell = ///
cell.collectionView.delegate = self
cell.collectionView.dataSource = self
之后,您就可以在vc中实现cellForItemAt
了,然后执行
let collecCell = ///
collecCell.button.addTarget//////
@objc func buttonClicked(_ bt:UIButton) {}
关于是否可以为该项目使用tag
属性
答案 1 :(得分:0)
请尝试以下操作:
在tableView
cellForRowAtIndexPath
方法中:
cell.yourCollectionView.tag = indexPath.row
在CollectionView
cellForRowAtIndexPath
方法中:
cell.yourBtn.tag = collectionView.tag * 2000 + indexPath.item
在“按钮操作”中,请输入:
let collectionViewTag = sender.tag / 2000
let index = sender.tag % 2000
它可能会帮助您。谢谢。