Search code examples
iosobjective-cuicollectionviewuigesturerecognizeruistoryboardsegue

UICollectionView prepareForSegue tapping UIImageView by gesture


I used a UICollectioView to load Images with a NBMutableArray from web and working well.

Now adding a Tap Gesture Recognizer on my UIImageView and i will pass the information to other view like a segue identifier example:

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

    if([@"getImage" isEqualToString:segue.identifier]) {
        NSIndexPath *index = [self.collectionView indexPathForCell:sender];
        [[segue destinationViewController] setLinkImg:(arrayCollectionImages)[index.row][@"image"]];
    }

In MyStoryBoard i used this:

enter image description here

if I leave only this function my app go to crash when tap on image.

any body know how can do that?


Solution

  • No need to add Tap Gesture Recognizer to UIImageView. Just connect 'Triggered Segues' of CollectionCell to your destination ViewController. So that sender will be CollectionCell in *- (void)prepareForSegue:(UIStoryboardSegue )segue sender:(id)sender method.

    enter image description here