在集合上按segue点击

时间:2014-08-31 20:24:40

标签: ios objective-c iphone uicollectionview

我已将我的collectionViewCell中的push segue连接到storyboard中的viewController,但是当单击一个单元格时没有任何反应。我该怎么做才能做到这一点?

prepareForSegue

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{


    if ([segue.identifier isEqual:@"toHomeProfile"])
    {
        HomeProfileViewController * dvc = segue.destinationViewController;
        self.selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] firstObject];


        dvc.imageArray = [[NSMutableArray alloc]init];
        dvc.imageArray = [imageDic objectAtIndex:self.selectedIndexPath.item];


    }
}

viewDidLoad中

- (void)viewDidLoad
{
   [super viewDidLoad];

    CHTCollectionViewWaterfallLayout *layout = [[CHTCollectionViewWaterfallLayout alloc] init];

    layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    layout.headerHeight = 0;
    layout.footerHeight = 0;
    layout.minimumColumnSpacing = 5;
    layout.minimumInteritemSpacing = 5;
    self.collectionView.collectionViewLayout = layout;


    _collectionView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    _collectionView.dataSource = self;
    _collectionView.delegate = self;
    _collectionView.backgroundColor = [UIColor whiteColor];
    [_collectionView registerClass:[CHTCollectionViewWaterfallCell class]
    forCellWithReuseIdentifier:CELL_IDENTIFIER];

}

1 个答案:

答案 0 :(得分:0)

在UICollectionViewDelegate协议中查看collectionView:didSelectItemAtIndexPath:

https://developer.apple.com/library/ios/documentation/uikit/reference/UICollectionViewDelegate_protocol/Reference/Reference.html

另外,在发布前快速谷歌! 3秒的搜索引导我

Handling Tap Gesture in a UICollectionView