Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to know indexpath of UITableView.visibleCells?

NSArray * arrayOfVisibleTVC=[BNUtilitiesQuick ListController].tableViewA.visibleCells; NSLog(@"array : %@", arrayOfVisibleTVC); 

will display

"<UITableViewCell: 0x76c22a0; frame = (0 0; 320 75); autoresize = W; layer = <CALayer: 0x76bf770>>", "<UITableViewCell: 0x76cfec0; frame = (0 75; 320 75); autoresize = W; layer = <CALayer: 0x769d260>>", "<UITableViewCell: 0xe245f70; frame = (0 150; 320 75); autoresize = W; layer = <CALayer: 0xe245ed0>>", "<UITableViewCell: 0xe248980; frame = (0 225; 320 75); autoresize = W; layer = <CALayer: 0xe2488c0>>", "<UITableViewCell: 0xe24afa0; frame = (0 300; 320 75); autoresize = W; layer = <CALayer: 0xe24aee0>>" 

and with this

UITableViewCell * lastObjectOfArray=arrayOfVisibleTVC.lastObject; int indexpathLastObject= (lastObjectOfArray.frame.origin.y/new.frame.size.height); 

I know the last of arrayOfVisibleTVC.lastObject that I use to get indexpath. but I think there is an another way to get indexpath of TableViewcell that showed.. any one can help me?

so I can get indexpath of cell as integer

like image 656
user4951 Avatar asked Nov 30 '11 06:11

user4951


People also ask

What is indexPath in Tableview Swift?

Swift version: 5.6. Index paths describe an item's position inside a table view or collection view, storing both its section and its position inside that section.

What does indexPath row return?

row will be 0. Then it will be 1, then 2, then 3 and so on. You do this so that you can get the correct string from the array each time.


2 Answers

Here is method in UITableView class:

objective-c

- (NSArray *)indexPathsForVisibleRows 

Swift

public var indexPathsForVisibleRows: [NSIndexPath]? { get } 
like image 66
Ramis Avatar answered Sep 19 '22 01:09

Ramis


UITableView has a method to find the indexPath of a cell:

- (NSIndexPath *)indexPathForCell:(UITableViewCell *)cell 

Just iterate over your visible cells array and pass each cell to get the index path.

for (UITableViewCell *cell in arrayOfVisibleTVC) {   NSIndexPath *path = [[BNUtilitiesQuick ListController].tableViewA indexPathForCell:cell];   NSLog(@"%@", path); } 
like image 26
sosborn Avatar answered Sep 23 '22 01:09

sosborn