Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView: Run code when tableFooterView is displayed?

I'm using the UIView tableFooterView of in my UITableView to show a "Loading more" label at the bottom of my table. When the UIView in tableFooterView is shown, I need to start some lazy download of content. How do I know when the tableFooterView is displayed?

like image 363
dhrm Avatar asked Feb 01 '12 11:02

dhrm


Video Answer


2 Answers

Instead of determining when the footer view will show you could check when the last row of the table is being requested and load the data then. The number of times a user scrolls to the very last row without scrolling down to see the footer are probably very few. The effect will be the same, i.e. you know when the user has scrolled to the bottom and you should load more data.

This can quite easily be implemented in tableView:cellForRowAtIndexPath:. By keeping track of what IndexPath is the last one, and updating it every time new rows are added or deleted, you can simply check if the IndexPath of the requested cell is the same as the IndexPath of the last row and trigger the lazy loading of more data from there, the same way you are currently doing it.

like image 162
David Rönnqvist Avatar answered Nov 15 '22 18:11

David Rönnqvist


You can convert footer's frame to window coordinates and compare them. When footer is hidden then it assume that it has Y origin coordinates > 480 (for portrait mode), when footer will appear then Y origin coordinates < 480. You can make comparison in didScroll method.

Thanks, hope this help you.

See method convertRect:toView:

like image 23
beryllium Avatar answered Nov 15 '22 17:11

beryllium