0

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.

Harshit Gupta
  • 1,200
  • 12
  • 27

2 Answers2

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?

Community
  • 1
  • 1
Saad
  • 8,857
  • 2
  • 41
  • 51
  • The links were very informational @saad, but i think they doesnot solve my problem. could you please suggest me how can solve the issue? – Harshit Gupta May 10 '12 at 11:14
  • as this method tells that app is going to be killed. so u have to implement the receive memoery warning messege and release the the IBOUTlet objects like [self.submitButton = nil]; [self.textView = nil]; etc – Saad May 10 '12 at 11:19
  • thats ok @saad, but what about the slowlyness? As the no of images keep on increasing the time being taken to load the images to scroll view also increases. This is how app became damn slow due to the former approach. – Harshit Gupta May 10 '12 at 11:22
  • i suggest u to use Table view instead of scroll view, as it autometically manages the memory usage of UI items. use customcell to show your image – Saad May 10 '12 at 11:35
  • @saad the su[ppose there are 20 images. They are shown in uiscrollview thats moves horizinatlly. when then user swipes, he is taken to next photo. As same we look photos in iphone'd default photo app. How can i implement tableview there. After watching the deafult iphone photo app, i was wonder that it shows all images, no matter how fast you scroll. no doubt initially the image is shown as blurred but soon it becomes ok and viewable. – Harshit Gupta May 10 '12 at 11:43
  • u mean u have implemented page control? – Saad May 10 '12 at 11:45
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/11101/discussion-between-shaifgupta-and-the-saad) – Harshit Gupta May 10 '12 at 11:48
  • 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 doesnot loads the images so fast also scrolling has become rough. – Harshit Gupta May 14 '12 at 06:18
0

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.

Mateus
  • 2,640
  • 5
  • 44
  • 62
  • 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 doesnot loads the images so fast also scrolling has become rough. – Harshit Gupta May 14 '12 at 06:18