0

I need to determine section in UITableView based on CGPoint. With section I mean section header + cells + section footer. There are only methods rectForHeaderInSection: and rectForFooterInSection: but nothing for whole section. Thanks.

user1518183
  • 4,651
  • 5
  • 28
  • 39
  • Are you trying to do this based on a users tap or for drawing something in a specific area? What you are trying to achieve may help in answering this correctly. – bluemoon Apr 26 '14 at 23:27

1 Answers1

0

You would have to manually iterate all possible sections and determine if a point exists for a given section.

There is a rectForSection: method on UITableView's that should combine the rectangles of the section header, cells, and footer. You could emulate that by doing a CGRectUnion of the rectForHeaderInSection: and rectForFooterInSection: for a given section (assuming those both existed).

NSInteger tappedSection = -1;
for (NSInteger section = 0; section < tableView.numberOfSections && tappedSection < 0; section++) {
    CGRect sectionRect = [tableView rectForSection:section];
    if (CGRectContainsPoint(sectionRect, somePoint)) {
        tappedSection = section;
    }
}
if (tappedSection >= 0) {
    NSLog(@"Tapped: %d", tappedSection);
}
Neil
  • 1,813
  • 1
  • 12
  • 20