ios - 在 UICollectionView 选择上选择 UITableView

标签 ios uitableview uicollectionview didselectrowatindexpath

我在 UITableViewCell 中有一个 UICollectionView。当我选择 tableView 行时,我不希望调用 UICollectionViewdidSelectItemAtIndexPath: 方法。相反,我希望调用 UITableViewdidSelectRowAtIndexPath: 方法。我如何在 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/

相关文章:

iphone - 为 UITableView 创建节索引标题的性能问题

ios - CollectionView 单元格大小限制

objective-c - RestKit 图片上传

ios - View 高度的布局不明确

ios - 钛-无法停止iOs后台进程

iphone - iOS 5 : UITableView cells are not scrolling smooth

ios - 我的应用程序会运行 iPhone 4 或更低版本吗?

ios - UICollectionView 自动高度

ios - 更改 UISlider 轨道图像的 alpha?

ios - 如何改变 UITextField 的形状?