Loading a UIScrollView like a UiTableView

老子叫甜甜 提交于 2019-12-12 03:15:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!