Created
April 19, 2013 01:46
-
-
Save linktoming/5417543 to your computer and use it in GitHub Desktop.
How to get index path from a button inside uicollectionviewcell
http://stackoverflow.com/questions/13966291/achieve-button-click-in-uicollectionview?answertab=votes#tab-top
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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]; | |
} |
Yes, I found that it can be used. Thanks wuxfheb !!
Thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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...
}