我在 UITableViewCell
中有一个 UICollectionView
。当我选择 tableView
行时,我不希望调用 UICollectionView
的 didSelectItemAtIndexPath:
方法。相反,我希望调用 UITableView
的 didSelectRowAtIndexPath:
方法。我如何在 didSelectItemAtIndexPath:
中调用 didSelectRowAtIndexPath:
?
最佳答案
swift 3
首先设置以下内容
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let parentCell: QMatrixCell? = collectionView.superview?.superview as! QMatrixCell?
parentCell?.delegate.collectionViewDidSelectedAtCell(cell: parentCell!)
}
并在包含表格 View 的 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/