Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
284 views
in Technique[技术] by (71.8m points)

iphone - Get Cell position in UITableview

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);
     }  
}

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

question from:https://stackoverflow.com/questions/6623957/get-cell-position-in-uitableview

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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 : %@ 

",currentCell.textLabel.text);

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...