Skip to content

Instantly share code, notes, and snippets.

@linktoming
Created April 19, 2013 01:46
Show Gist options
  • Save linktoming/5417543 to your computer and use it in GitHub Desktop.
Save linktoming/5417543 to your computer and use it in GitHub Desktop.
(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CellId" forIndexPath:[indexPath row]];
[[cell myButton] addTarget:self action:@selector(myClickEvent:event:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
(IBAction)myClickEvent:(id)sender event:(id)event {
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:_myCollectionArray];
NSIndexPath *indexPath = [_myCollectionArray indexPathForItemAtPoint: currentTouchPosition];
}
@wuxfheb
Copy link

wuxfheb commented Apr 22, 2015

can use this way?

  • (IBAction)deleteCellBtnTapped:(UIButton )sender
    {
    UICollectionViewCell
    cell = (UICollectionViewCell*)[[sender superview] superview];
    NSIndexPath *indexPath = [self.collectionView indexPathForCell:cell];

    if (indexPath == nil) {
    assert(false);
    return;
    }

// do stuff...
}

@akuvan
Copy link

akuvan commented Sep 8, 2015

Yes, I found that it can be used. Thanks wuxfheb !!

@StasBelousov
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment