开发者

how to add more than 100 uiimageviews in uiscrollview

i have an uiscrollview and i add one by one uiimageviews but when i add more than 40 objects i have problem with memory i guess and the app crashes...what should i do? i am trying to make an app like photo viewer from apple! Help please!

i do not want thumbnais i just want to show the next image when the user flick from one to another but i have to unload the previous image and show the next one

i remove the previous like this

UIImageView l;

l=[[scroll subviews] objectAtIndex:0];
[l removeFromSuperview];
l=nil;

and then i add the next one like this

[scroll insertSubview:开发者_如何学PythonimageView atIndex:counter];

but i see a black background no image

please help!


The best way to do this is to load a few of the images at a time into a table view. In each cell of the table, put three thumbnails. You'll need to make a custom cell. That way, the table cells will be de-queued and the memory re-used. Check the Facebook Three20 project, I think they've implemented it like this, so you'll have some code to work with.

http://joehewitt.com/post/the-three20-project/


Ask yourself, do you really need to load all 100 images into memory? Why not just load a few images at a time in the background, depending on what image the user has scrolled to?


Don't do it that way.

If you want to display a 100 small thumbnails, resize them first with core graphics. Then they take up much less memory when you display 100 images at once.

If you want to display a 100 large images but only one is visible at a time, have 1 or 2 image views that load up the current and next images, and animate them in a clever way to make it look an endless stream. You can still use a scrollView, just monitor it's position and position your image views appropriately.


There is exactly an apple sample code that do what you want. Look for the PageControl sample, it is already implemented. Basically the slider gets the image controller from an array of controllers; among other things, when the scroller changes to the previous or next image, controllers are added and removed from this array dynamically to keep memory footprint low. Have a look at the sample code, it is quite simple. Hope it helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜