6

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?

Rayfleck
  • 12,116
  • 8
  • 48
  • 74
user1179681
  • 165
  • 1
  • 3
  • 10
  • have you searched a bit ? what's the result for your research ? did you try something ? –  Feb 01 '12 at 10:20

4 Answers4

15

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

lukas
  • 2,300
  • 6
  • 28
  • 41
Mihai Panţiru
  • 513
  • 3
  • 16
  • can you please tell me that how the tableview is finished loading Data, here i am not subclassing the UITableView – user1179681 Feb 01 '12 at 10:36
  • You can check this question, http://stackoverflow.com/questions/1483581/get-notified-when-uitableview-has-finished-asking-for-data, probably will help you. – Mihai Panţiru Feb 01 '12 at 10:44
  • Yes,i already gone through that but in that they solved that problem by subclassing UITableView but that is not possible for me – user1179681 Feb 01 '12 at 10:46
  • Sorry but I don't know a better solution. You want to know when the scroller stops or what? Try scrollViewDidEndDecelerating: and you will know when the loading is done. And why you can't subclass UITableView? – Mihai Panţiru Feb 01 '12 at 10:56
  • i want to know when the tableview completed loading the visible cells loading – user1179681 Feb 01 '12 at 10:59
3

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

Piyush Kashyap
  • 1,965
  • 1
  • 14
  • 16
1

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

Ilanchezhian
  • 17,426
  • 1
  • 53
  • 55
  • Yes, *usually* is that. However it can be `ceil(tableView's height / cell row height ) + 1`. Anyway these formulas are only to find the minimum or maximum number of visible. To find the *current* number of visible cells it is necessary to know the scroll offset :) – nacho4d Dec 01 '14 at 09:12
1

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?

Antonio MG
  • 20,382
  • 3
  • 43
  • 62