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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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);
}