我需要确定基于CGPoint在UITableView的部分。 随着部分我的意思是节头+细胞+页脚节。 只有方法rectForHeaderInSection:和rectForFooterInSection:但没有对整段。 谢谢。
Answer 1:
你将不得不手动遍历所有可能的部分,并确定是否存在点对于给定的部分。
有一个rectForSection:
上的UITableView的方法应该结合节头,细胞和页脚的矩形。 你可以效仿,通过做的CGRectUnion rectForHeaderInSection:
和rectForFooterInSection:
对于给定的部分(假设这些都存在)。
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);
}
文章来源: Determine section in UITableView from CGPoint