Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to access from UICollectionViewCell the indexPath of the Cell in UICollectionView

Tags:

i want to animate the UICollectionViewCell when action is called.
i have done UICollectionViewCell in Interface Builder, the UICollectionView also. Now i want to get the correct indexPath at my actionBtnAddToCard method.

thats the way i try it now (method in ProduktViewCell.m):

- (IBAction)actionAddToCart:(id)sender {     XLog(@"");      // see this line     NSIndexPath *indexPath = ??** how can i access the correct indexPath**??;     SortimentViewController *svc = [[SortimentViewController alloc] initWithNibName:@"SortimentViewController_iPad" bundle:[NSBundle mainBundle]];     [svc.collectionViewProdukte cellForItemAtIndexPath:indexPath];      [svc collectionView:svc.collectionViewProdukte didSelectItemAtIndexPath:indexPath]; }  

SortimentViewController is the viewController which inherits the UICollectionView.
how to acces the correct indexPath?

UPDATE 1: edited post for better understanding.

like image 286
brush51 Avatar asked Dec 14 '12 08:12

brush51


People also ask

How do I get the IndexPath of a cell Swift?

add an 'indexPath` property to the custom table cell. initialize it in cellForRowAtIndexPath. move the tap handler from the view controller to the cell implementation. use the delegation pattern to notify the view controller about the tap event, passing the index path.

How do I get a cell in CollectionView?

In Swift 4 you can get the cell of CollectionView with:let indexPath = IndexPath(item: 3, section: 0); if let cell = myCollectionView .

What is IndexPath section in Swift?

Swift version: 5.6. Index paths describe an item's position inside a table view or collection view, storing both its section and its position inside that section.


1 Answers

- (IBAction)actionAddToCart:(id)sender {    NSIndexPath *indexPath;    indexPath = [self.collectionView indexPathForItemAtPoint:[self.collectionView convertPoint:sender.center fromView:sender.superview]];     ... } 
like image 151
carmen Avatar answered Sep 29 '22 06:09

carmen