2013-10-22 43 views
1

我有一個自定義的CollectionViewCell類,然後我在CollectionView中生成了一些這些內容。當ViewCell被觸摸時,我還添加了一個模態輪廓。如何激活模態切入點時獲得哪個單元格的id(或索引路徑)。獲取UICollectionViewCell的indexPath

我看到這裏,有人建議我加入到ViewCell.m文件的方法

-(void)collectionView: (UICollectionView*)collectionView didSelectItemAtIndexPath: (NSIndexPath*)indexPath{ 
//get indexpath variable in here 
} 

但這種方法似乎並不被獲取調用。任何人都可以幫助我,當CollectionViewCell具有模態segue來獲取indexpath時,需要調用什麼方法。

感謝,

回答

1

如果您已經添加到您的細胞意見處理觸摸發射了SEGUE,那麼collectionViewCell從未有機會獲得的觸感。

如果您想要collectionViewCell來處理它,通過禁用它們的行爲來啓動segue,使您的單元格的子視圖變爲純裝飾。 (例如,如果它們是按鈕,並且「touchUpInside」會觸發segue,則將它們更改爲視圖,根本沒有任何觸摸處理。)。

然後觸摸將通過視圖層次結構傳遞,直到CollectionViewCell處理它爲止,這與collectionView:didSelectItemAtIndexPath:方法一樣。

+0

感謝格式升級Vineet! –

0

的方法是委託類集合視圖對象的回調:

-(void)collectionView: (UICollectionView*)collectionView didSelectItemAtIndexPath: (NSIndexPath*)indexPath 

所以,你應該對委託類你收集鑑於.m文件執行。

相關問題