user1179681
user1179681

Reputation: 165

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?

Upvotes: 6

Views: 8017

Answers (4)

Mihai Panţiru
Mihai Panţiru

Reputation: 523

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

Upvotes: 15

Piyush Kashyap
Piyush Kashyap

Reputation: 1965

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

Upvotes: 3

Antonio MG
Antonio MG

Reputation: 20410

Can you take the size of the visible part of the table, and then the size of one cell, and divide them to know how many of them fit in the screen?

Upvotes: 1

Ilanchezhian
Ilanchezhian

Reputation: 17478

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

Upvotes: 1

Related Questions