Your tap position is the location in the header, not the cell, so it will never match the indexPath cell.
Perhaps you could set the tag to represent avatar as the section number in viewForHeaderInSection , and then get the section number in handleTapGesture via sender.view.tag . For instance:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { ... UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)]; tapGesture.numberOfTapsRequired = 1; avatar.tag = section;
source share