在UITableview中获取Cell位置 [英] Get Cell position in UITableview

查看:114
本文介绍了在UITableview中获取Cell位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在tableview中获取单元格的位置。从这段代码我得到单元格位置

I am trying to get position of cell in tableview. from this code i am getting cell position

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)。

it is calculating y axes of cell in tableview but my problem is i want to get the cell position in the visible area of tableview rect. ie if table view has size cgrectmake(0,0,200,500) and cell height is 100 pixels. so tableview will show 5 rows. if i scroll down and select 7th row. i will get its y axes 700. but the cell will be within (0,0,200,500) frame. How can I get cell location within this frame (0,0,200,500).

推荐答案

注意:我希望,问题可能会再次更新,请使用可能适用于您的其他答案。

NOTE:I hope, question might have updated again, please use the other answers that may applicable to you.

你可以使用 visibleCells 方法,该方法将返回tableview中当前可见的单元格:

You can use the visibleCells method which will return the currently visible cells in your tableview:

NSArray *visibleCellsList=[tableview visibleCells];

for (UITableViewCell* currentCell in visibleCellsList) {

    NSLog(@"cell : %@ \n\n",currentCell.textLabel.text);

}

这篇关于在UITableview中获取Cell位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆