【发布时间】:2011-10-01 05:23:09
【问题描述】:
我正在尝试获取单元格在表格视图中的位置。从这段代码中我得到了单元格的位置
int numberOfSections = [UITableView numberOfSections];
int numberOfRows = 0;
NSIndexPath *tempIndexPath = nil;
UITableViewCell *tempCell = nil;
for(int i=0;i<numberOfSections;i++)
{
numberOfRows = [UITableView numberOfRowsInSection:i];
for(int j=0;j<numberOfRows;j++
{
tempIndexPath = [NSIndexPath indexPathForRow:j inSection:i];
tempCell = [UITableView cellForRowAtIndexPath:tempIndexPath];
NSLog("Y postion for cell at (Row = %d,Section = %d) is :%f",tempCell.frame.origin.y);
}
}
它正在计算 tableview 中单元格的 y 轴,但我的问题是我想在 tableview rect 的可见区域中获取单元格位置。即如果表视图的大小为 cgrectmake(0,0,200,500) 单元格高度为 100 像素。所以 tableview 将显示 5 行。如果我向下滚动并选择第 7 行。我将得到它的 y 轴 700。但单元格将在 (0,0,200,500) 框架内。 如何获取此框架内的单元格位置 (0,0,200,500)。
【问题讨论】:
-
您的日志错误NSLog("(Row = %d,Section = %d) 单元格的 Y 位置为 :%f",tempCell.frame.origin.y);
标签: iphone uitableview