Is there any way to know if a tableview cell is currently visible?
I have a tableview whose first cell(0) is a uisearchbar.
If a search is not active, then hide cell 0 via an offset.
When the table only has a few rows, the row 0 is visible.
How to determine if row 0 is visible or is the top row?
Is there any way to know if a tableview cell is currently visible? I
Share
UITableViewhas an instance method calledindexPathsForVisibleRowsthat will return anNSArrayofNSIndexPathobjects for each row in the table which are currently visible. You could check this method with whatever frequency you need to and check for the proper row. For instance, iftableViewis a reference to your table, the following method would tell you whether or not row 0 is on screen:Because the
UITableViewmethod returns theNSIndexPath, you can just as easily extend this to look for sections, or row/section combinations.This is more useful to you than the
visibleCellsmethod, which returns an array of table cell objects. Table cell objects get recycled, so in large tables they will ultimately have no simple correlation back to your data source.