How to reload a UITableView for more data?
I have UITableView, which I fill from a JSON Query.
I fill it with Private Messages and it works.
The JSON Query has the properties of "site" in which I get for every site 20 PMs. So at the beginning I got Site=0 and got 20PMS which are loaded.
Now I wanna have the features like in the Email-app (i believe I saw it there): When you scroll down and reach the end (in my app reached the 20. PM), the application should load the next 20 and so on and so开发者_C百科 on.
Any ideas how to realize?
Save the index path of your last row and implement
[UITableView reloadRowsAtIndexPaths:withRowAnimation:]
Or you can use scrollToRowAtIndexPath:atScrollPosition:animated:
scrollPosition
A constant that identifies a relative position in the receiving table view
(top, middle, bottom) for row when scrolling concludes.
See “Table View Scroll Position” a descriptions of valid constants in docs
And once you get you last scroll position just reload your table view [tableView reloadData]
But there is problem i guess once you reload the data i think after reloading(I am not sure) tableView it will take you to first row again then you can always save the lastIndexpath of that tableView and after reloadData just scrollToRowAtIndexPath:atScrollPosition:animated: or you can use scrollToNearestSelectedRowAtScrollPosition:animated:
I think you can implement feature like email app using your custom logic. What you do is keep the last row of tableview for loading more data. There should be message like "Load more..." in that last row. Whenever user touches that row, you should load more data and update tableview.
Stephen James and his colleagues at Key Options Development came across a similar problem: http://blog.keyoptions.co/tableview-with-automatic-load-more
They have built a sample app (ContinousTableview) that should be of some help to you. The source code is available at GitHub: https://github.com/stephenjames/ContinuousTableview
精彩评论