问题描述
我需要基于CGPoint确定UITableView中的部分。对于部分,我指的是部分标题+单元格+部分页脚。只有rectForHeaderInSection:和rectForFooterInSection:方法,但整个部分都没有。谢谢。
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.
推荐答案
您将必须手动迭代所有可能的节并确定给定节是否存在点。
You would have to manually iterate all possible sections and determine if a point exists for a given section.
在UITableView上有一个 rectForSection:
方法,该方法应结合节标题,单元格和页脚的矩形。您可以通过对给定部分进行 rectForHeaderInSection:
和 rectForFooterInSection:
的CGRectUnion来模拟(假定两者都存在)
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);
}
这篇关于从CGPoint确定UITableView中的部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!