开发者

Improve performance in scrollview

开发者 https://www.devze.com 2023-01-06 18:54 出处:网络
I am new to programming. I have a paging enabled scroll view with many pages (up to ten) and on every page I have a custom button. Every custom button has a custom image. Everything I have made in Int

I am new to programming. I have a paging enabled scroll view with many pages (up to ten) and on every page I have a custom button. Every custom button has a custom image. Everything I have made in Interface Builder. When I load the view controller containing this scroll view, it takes a lot of time to load it because it loads all the pages. How can I improve the load time? Can I implement the lazy loading technique in my case? If yes, how exactly, because I am a beginner. Thank you i开发者_如何转开发n advance!


You definitely can. There are several examples of scroll views where the content is loaded/unloaded dynamically as you scroll through.

The following blog post helped me get going with this: http://cocoawithlove.com/2009/01/multiple-virtual-pages-in-uiscrollview.html

You also want to make sure NOT to use [UIImage imageNamed:] unless you must. This method has internal caching, which is very flakey and unreliable, and if you load enough number of big images, your app will be decapitated fairly quickly -- instead use e.g. [UIImage imageWithContentsOfFile:]. There is a discussion of this on SO here: Difference between [UIImage imageNamed...] and [UIImage imageWithData...]? -- if you're unsure on how to approach things, read that and make up your mind afterwards.

Hope that helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消