The best advice than I can give you in this situation is to be sensible about when exactly you call - (NSArray *)visibleCells
on the tableView
.
scrollViewDidScroll
gets called a hell of a lot. If you are then calling .visibleCells
on the tableView
every time, it is no wonder it is impacting your performance as much as it is.
My advice is that, considering you obviously know the height of your table view cells, (either declared in code or in IB), I would use this to your advantage. Note that this will not really work if your cells vary in height.
Up front, in your checkVisibleCells method, I would add this:
- (void)checkVisibleCells
{
CGFloat newContentOffsetY = self.tableView.contentOffset.y;
BOOL tableViewHasScrollFarEnough = newContentOffsetY > lastCheckedContentOffsetY + MysteriousViewControllerTableViewCellHeight;
tableViewHasScrollFarEnough = tableViewHasScrollFarEnough || self.tableView.contentOffset.y < self.lastCheckedContentOffsetY - MysteriousViewControllerTableViewCellHeight;
if (tableViewHasScrollFarEnough)
{
return;
}
self.lastCheckedContentOffsetY = self.tableView.contentOffset.y;
// ... the rest of the method
}