![](/img/trans.png)
[英]How to add multi arrays in one section of Collection View Cell which that collection view inside tableView cell?
[英]How to find out which collection view cell is tapped inside collection view cell
我有一個表視圖,里面有一個集合視圖。 我想找出哪個集合視圖單元被點擊,以及相應的表視圖單元格的indexpath.row。(現在我能夠從didSelectRowAtIndexPath()獲取集合視圖單元格的indexpath.row但是無法找到哪個表視圖單元格對應的單元格。)
試試下面的代碼,讓我知道它是否適合你:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
CGRect frame = [collectionView convertRect:cell.frame toView:tblView];
NSIndexPath *tblIndexPath = [tblView indexPathForRowAtPoint:frame.origin];
}
首先進行一些修正。
集合視圖委托方法是didSelectItemAt而不是didSelectRowAtIndexPath()。 此外,由於您正在使用集合視圖通過使用indexPath.item
而不是indexPath.row
獲取項目編號(您可以使用row
但集合視圖沒有行,它具有項目集合。因此使用item
是直觀的)
現在,您可以在表視圖的 cellForRowAtIndexPath:
添加cell.tag = indexPath.row
現在在集合視圖中委托方法collectionView(_:didSelectItemAt:) :
您可以使用self.tag
來了解集合視圖所在的表視圖單元格。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.