问题
I am developing a iPhone photo app in which there is one view, where I am showing all the images taken through that app with the help of uiscrollview. First I simply loaded the scrollview with all the present images. But it made the app slow and also caused the crash giving the following warning:
Received memory warning. Level=2
I googled a lot and found that the reason for so may be loading such heavy images all together on a view are resulting in memory warning and crash afterwards. So I opt for the concept of lazy loading.
In which I was just loading the three images one at the center(currently shown to user) and the other two on either sides. I did that in following way:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
pageNum = (int)(scrollView.contentOffset.x / scrollView.frame.size.width);
pageNumber = floor(pageNum);
[self setImages:pageNumber]; //setting three images
}
Now there is no crash, no memory warning but the scroll has become quite rough with lots of jerks.
Please suggest me how to get rid the roughness or to show all the images same as iPhone 's default photo app.
Help is much appreciated.
Note: 1. No of images not known, can be unlimited. 2. Xcode 3.2.6 3. ios sdk 4.3
Please consider the link [link]https://www.dropbox.com/sh/h0vwnhhx1acfcb5/W2TQ638udh The link shows a video in which i have shown a photo scroller with lazy loading embedded. Some times it doesn't loads the images so fast also scrolling has become rough.
回答1:
this is low memry warning see these threads
iPhone OS Memory Warnings. What Do The Different Levels Mean?
http://www.iphonedevsdk.com/forum/iphone-sdk-development/92778-received-memory-warning-level-2-17mb-used.html
iPhone Memory warning level=2
"Received memory warning. Level=2" with 4.x?
回答2:
Ok.If i understood well,you want to display the images in a UITableView,as in a sequence and make the table scroller works normally.
I used to have the same problem in one of my projects,i solved it by not downloading the image and simple displaying it,to be more clearly i divided in 3 steps:
1-Create a XML file to store all image's web address and of course id's.
2-Using NSXMLParser,get all images web address and add it to an NSArray,after display it on a UITableView.You can customize the tableView to all images look like you want to design it.
3-On the UITableView method add an UIWebView(THIS IS THE KEY).Load the image address to this webView.
来源:https://stackoverflow.com/questions/10532654/with-lazy-loading-in-my-my-iphone-app-photo-scroll-become-rough-jerks