在使用自定义UITableView
作为节标题的纯UIView's
中,有一种方法可以计算:
我希望在这里计算:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
最佳答案
您可以通过从tableView:numberOfRowsInSection:
协议调用UITableViewDataSourceDelegate
方法来找到该部分中的行数。您可以使用tableView:heightForRowAtIndexPath:
协议中的UITableViewDelegate
方法获取该部分中每一行的高度。将所有行的高度加起来,就可以得到所需的距离。
假设您有对tableview和section的引用,您的代码将看起来像这样。
float totalHeight = 0;
for (int i = 0; i < [tableViewDataSourceDelegate
tableView:tableView
numberOfRowsInSection:section]; i ++) {
totalHeight += [tableViewDelegate
tableView:tableView
heightForRowAtIndexPath:[NSIndexPath
indexPathForRow:i
inSection:section]];
}
还没有机会测试此代码,但它应该可以工作[tm]。
编辑
仅当标题位于顶部时,这才起作用。