我在UITableViewCell
內有UICollectionView
。當我選擇一個tableView
行時,我不希望調用UICollectionView
的didSelectItemAtIndexPath:
方法。相反,我想didSelectRowAtIndexPath:
方法UITableView
被調用。如何在didSelectItemAtIndexPath:
中撥打didSelectRowAtIndexPath:
?在UICollectionView選擇上選擇UITableView
1
A
回答
1
設置collectionView.allowsSelection = NO
禁用選擇。
或didSelectItemAtIndexPath
方法,抓住的UITableViewCell和調用該委託其爲具有的UITableView表視圖:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *parentCell = collectionView.superview;
[parentCell.delegate collectionViewDidSelectedAtCell:parentCell];
}
// IN your view controller that has the table view
- (void)collectionViewDidSelectedAtCell:(UITableViewCell *)cell{
NSIndexPath *index = [self.tableView indexPathForCell:cell];
[self tableView:self.tableView didSelectRowAtIndexPath:index];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
1
夫特3
首先設置以下
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let parentCell: QMatrixCell? = collectionView.superview?.superview as! QMatrixCell?
parentCell?.delegate.collectionViewDidSelectedAtCell(cell: parentCell!)
}
並在包含您的tableview的控制器中執行以下操作
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單元格中設置委託。
相關問題
- 1. UICollectionView的選擇
- 2. iOS UICollectionView選擇
- 3. 動畫uicollectionview上選擇
- 4. UICollectionView選擇和取消選擇問題
- 5. UITableView選擇 - 多選
- 6. UICollectionView不能選擇
- 7. 的UITableView選擇
- 8. UITableView頭選擇
- 9. UITableView選擇和取消選擇
- 10. UITableView多重選擇
- 11. UITableView pushViewController選擇行
- 12. 當UICollectionView嵌套在UITableVIew中時不能進行選擇
- 13. UICollectionView選擇不會持續
- 14. IOS UICollectionView選擇問題
- 15. UITableView didSelectRowAtIndexPath未在UIPageViewController上選擇
- 16. 最後選擇行在UITableView
- 17. 在UICollectionView中的選擇和取消選擇swift 2
- 18. UICollectionview在滾動時更改選擇/禁用選擇 - iOS
- 19. jQuery的選擇上選擇
- 20. 不能在UICollectionView選擇項編程
- 21. 切換UICollectionView單元格的選擇/取消選擇狀態 - Swift
- 22. UICollectionView選擇/取消選擇方法不觸發
- 23. UICollectionView方法deselectItemAtIndexPath不取消選擇剛選擇的項目
- 24. UICollectionView shouldSelectItemAtIndexPath = NO不會避免取消選擇舊選擇?
- 25. UITableView多選。自動選擇行隨機選擇行
- 26. 奇怪的UITableView選擇行爲,僅在長按之後選擇
- 27. UITableView崩潰行選擇
- 28. UITableView沒有正確選擇
- 29. 已選擇UItableview部分 - swift
- 30. 的UITableView選擇的onLoad
首先嚐試make collectionview選擇無 – Vvk
集合視圖的單元格是否可選?我的意思是你需要收集視圖的這些單元格可選 –
我不希望它們可選,但我希望它們可以滾動。我試圖禁用collectionView的userInteraction。在選擇時,'didSelectRowAtIndexPath:'最終被調用,但是,collectionView不滾動 – iOS