I have a collection view, and I am trying to get the index of the cell that I am peeking and poping from.


Currently I am using indexPathForItemAtPoint: however this always returns 0 no mater where I tap on the screen.


collection view controller:

- (void)viewDidLoad {
    [super viewDidLoad];
    [self registerForPreviewingWithDelegate:self sourceView:self.collectionView];

- (UIViewController *) previewingContext:(id <UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint) {

    CellEditViewController *CEVC = [self.storyboard instantiateViewControllerWithIdentifier:@"detail"]; //The view I want peek/pop to

    NSLog(@": %f,%f", .x, .y);
    NSLog(@"Index of: %lu", [[self.collectionView indexPathForItemAtPoint:] row]);

    [CEVC setPreferredContentSize:CGSizeMake(0.0, 3.0)];

    return CEVC;

- (void)previewingContext:(id <UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit {
    [self showViewController:viewControllerToCommit sender:self];

What I have tried

  • Creating a new location to identify the index cell.
  • Moving registerForPreviewingWithDelegate:sourceView: to where I create each cell.
  • Moving previewingContext:viewControllerForLocation: and previewingContext:commitViewController: to the cell view method, this did not work for other reasons.

Source link

No tags for this post.


Please enter your comment!
Please enter your name here