我有一個嵌入UIViewController的UICollectionView。我有一個自定義的UICollectionView單元格,在CollectionView中有一個按鈕。我想點擊按鈕,讓它推送一個細節視圖控制器,並傳遞一些數據。UICollectionView自定義單元格,當點擊一個UIButton時如何選擇Segue
我可以在我的主視圖控制器
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSArray *indexPaths = [self.collectionView indexPathsForSelectedItems];
NSIndexPath *index = [indexPaths objectAtIndex:0];
DetailController *destViewController = segue.destinationViewController;
}
如果我拍了拍細胞本身,這將工作通過prepareForSegue很容易得到這些細胞的保持。然而,我有一個UIButton我想要挖掘,我需要找到一種方法來鉤入indexPathsForSelectedItems ...現在,我的按鈕將無法正常工作,除非我實際上點擊它在第一個單元格。我是否需要在觸發點擊事件之前以編程方式選擇它所在的單元格?
我該怎麼做?我會在哪裏做這個?在視圖控制器上?或者在我的自定義UICollectionViewCell中點擊事件內?
檢查這個答案:http://stackoverflow.com/questions/13966291/achieve-button-click-in-uicollectionview?answertab=votes#tab-top – Mingming 2013-04-18 07:36:35