问题
Is there a way to load a UIScrollView in a similar way to how a UITableView is loaded - in other words, only load the visible 'cells'?
For my example I have a large scroll view which can be scrolled in any direction. Inside that are 'cells' which I add to the scroll view using code. The cells consist of data gathered from json feeds (one feed per cell). I would like to only load the feeds for the visible cells, and then cache the ones already loaded, so they don't need to be reloaded.
Is there a good method of doing this? Or is there another direction I should be taking to get this result?
A couple of answers have suggested a tiling approach, but I'm not sure that tiling is quite the right approach, since the whole cell needs to be loaded when part of it is visible. Another approach which google hints at is putting a UITableView within a UIScrollView, but I've yet to try this.
——————————----------------------
| | | < a 'cell' row in the scrollview
| - - - -| - - - - - - - - - - |
screen > | | |
| | |
—————————— |
| | < whole of scrollable area
| |
| |
| |
--------------------------------
回答1:
You are describing "tiling."
Take a look at Apple's sample code - it demonstrates an approach to tiling.
回答2:
You can use CATiledLayer.
https://stackoverflow.com/questions/tagged/catiledlayer
https://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CATiledLayer_class/Introduction/Introduction.html
来源:https://stackoverflow.com/questions/9220055/loading-a-uiscrollview-like-a-uitableview