index
is 0 because selectedIndexPath
is nil. You should be writing
CGPoint location = [gesture locationInView:grid_element];
NSIndexPath *selectedIndexPath = [grid_element indexPathForItemAtPoint:location];
if (selectedIndexPath != nil)
{
NSInteger index = selectedIndexPath.row;
}
P.S. Sorry for previous (incorrect) answer, I misunderstood.