Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect how many cells are visible in a UITableView

My table view covers part of the view. If I have 20 objects, I am displaying all of them in a tableview. But I want to know that how many cell are loaded that are visible to the user. (i.e. first 5 cells data is visible for me: when I scroll down, the remaining cells will load. Here I want to know without scrolling how many cell are loaded.)

Is this possible?

like image 836
user1179681 Avatar asked Feb 01 '12 10:02

user1179681


3 Answers

You can use [tableView visibleCells] count], which returns numbers of the table cells that are visible, if I understand correctly what you want.

like image 140
Mihai Panţiru Avatar answered Oct 03 '22 07:10

Mihai Panţiru


The below code will give you the array of indexpath of cells currently visible

NSArray *visiblePaths = [self.tableView indexPathsForVisibleRows];

after getting the index path you can easily access the cell at a particular indexpath

like image 34
Piyush Kashyap Avatar answered Oct 03 '22 08:10

Piyush Kashyap


Its usually : (tableView's height / cell row height ) + 1

like image 40
Ilanchezhian Avatar answered Oct 03 '22 08:10

Ilanchezhian