Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView's indexPathsForVisibleRows incorrect?

When I check for a table's visible indexPaths with 'indexPathsForVisibleRows' during UIScrollViewDelegate's scrollViewDidScroll and scrollViewDidEndDragging, it seems to be accurate.

But sometimes just when scrolling and dragging is ending and 'cellForRowAtIndexPath' is invoked, the call to 'indexPathsForVisibleRows' returns 0. There are rows visible on-screen so I know it can't be 0. As soon as this happens, I can invoke UITableView::visibleCells and get a non-zero value.

Why does this discrepancy exist?

like image 591
Justin Galzic Avatar asked Nov 04 '10 17:11

Justin Galzic


1 Answers

Did you tried calling methods in below sequence:

[MyTable visibleCells];
[MyTable indexPathsForVisibleRows];

There is a bug in iOS with indexPathsForVisibleRows. Use above two line code to get correct visible rows.

like image 143
Saroj Avatar answered Nov 17 '22 20:11

Saroj