我正在开发一个项目,其中我在 UITableViewCell 中有一个
我的 View 层次结构如下所示:UICollectionView
。
- TableViewCell
- Collection View
- CollectionView 单元格
- 按钮(我想访问它并知道 tagValue)。
- CollectionView 单元格
- Collection View
我有两个 TableView 单元格,每个 tableView 单元格中都有一个 UICollectionView
并且每个 UICollectionView
包含 4 个 UICollectionViewCell
,所以我想知道我的按钮在按下时包含在 UICollectionViewCell
中的确切 tagValue。
我还在 cellForItem atIndexpath TableView 单元格类 中将标记值赋予了按钮,就像这样
cell.button.tag = indexpath.item
而且我还为按钮提供了选择器。
最佳答案
试试这个:
删除此行:
cell.button.tag = indexpath.item
添加此功能
@IBAction func clickCollectionCellButton(sender : UIButton){
var cell: UICollectionViewCell? = (sender.superview?.superview as? UICollectionViewCell) //track your view hierarchy
var indexpath: IndexPath? = collectionView?.indexPath(for: cell!)
// do your additional work
}
关于ios - 我如何访问 TableView 单元格中包含的 CollectionView 单元格中的按钮标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44917280/