OGeek|极客世界-中国程序员成长平台

标题: ios - 在 UICollectionView 选择上选择 UITableView [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 10:29
标题: ios - 在 UICollectionView 选择上选择 UITableView

我在 UITableViewCell 中有一个 UICollectionView。当我选择 tableView 行时,我不想调用 UICollectionViewdidSelectItemAtIndexPath: 方法。相反,我希望 UITableViewdidSelectRowAtIndexPath: 方法被调用。如何在 didSelectItemAtIndexPath: 中调用 didSelectRowAtIndexPath:



Best Answer-推荐答案


swift 3

先设置如下

 func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    let parentCell: QMatrixCell? = collectionView.superview?.superview as! QMatrixCell?
    parentCell?.delegate.collectionViewDidSelectedAtCell(cell: parentCell!)
}

并在包含您的 tableview 的 Controller 中执行以下操作

extension TableViewController: SelectionCell{
 func collectionViewDidSelectedAtCell(cell : QMatrixCell){
    let index: IndexPath? = tableView.indexPath(for: cell)
    tableView(tableView, didSelectRowAt: index!);
 }
} 
protocol SelectionCell {
   func collectionViewDidSelectedAtCell(cell : QMatrixCell);
}

别忘了在你的 tableView 单元格中设置委托(delegate)。

关于ios - 在 UICollectionView 选择上选择 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35448927/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4