UITableViewCell中的UICollectionViewCell中的按钮点击操作

时间:2019-01-23 11:24:02

标签: swift uitableview uicollectionview uibutton uicollectionviewcell

我有这个层次结构。

  

UITableView-> UITableViewCell-> UICollectionView-> UICollectionViewCell-> UIButton。   如何使用swift4处理uibutton上的点击事件?

2 个答案:

答案 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

它可能会帮助您。谢谢。