i stuck with some issue of UITableView scrolling. I know that there are numbers of this question and some solutions. However from technical view like (how exactly to do that) i can't find solutions.
Well in my case scrolling is not so smooth because of images in it. It takes lots of time to load it from file. Also i create custom UITableViewCell and using XiB.
These images is using not 1 time but several, the good idea would be to keep them in memory and to load them just once from file. However in my case there could lots of images and app don't have so many memory to keep them. Maybe there are other way to load these images ?
Also images is PNG, maybe i should change type to JPG ?
I would appreciate if someone would give other solutions to improve this scrolling.
Thanks.
Related
My application suppose to show images in full screen and i have lots of images in my list(more than 500 images).
I'm adding image view in scroll view with horizontal scrolling and paging. But I'm facing memory issues as loaded images will eat my device memory?
What is the best way to load images.
Don't attempt to use a vanilla UIScrollView to show a ton of content, especially if you're just going to dump it all in at load-time. As you've seen, that will inevitably crash due to memory pressure.
At a minimum use UICollectionView, which will at least reuse cells and allow a minimum of assets to be in memory at one time. However, the problem of a smooth, low-memory photo collection view is one that many apps encounter, and can have a lot of implementation gotchas. I recommend looking for a well-built component rather than trying to reinvent that particular wheel.
I have a bunches of cell that contain UIImageView in UICollectionView and i've using setImageWithURL to load image in each cell, but if it load too much (i.e 100 cell) my app become crashing. Its definitely because of memory issues, i know this is not rare case in Mobile platform, but i still need help from experient guys.
I think it come from setImageWithURL (AFNetworking) problem, it still keep the catch from previous image link and bytheway i've using infinity scrolled, so the system will hold all the images, and memory can not stand. I need a solution for clear the cath images file or some thing to manage the memory. Any help ?
I'm an iOS newbie and for an app a view will have around 20 photos with a audio player under each so you can listen to someone speak about the images.
How do I go about with this? Would I just make a very long view controller with all the images and audio? It would be a lot of images in total as there are around 5 views with these images and audio.
Or is there a way to have this content elsewhere and get the app to pull the content into the view?
I hope I make sense. Any tutorials/ideas would be a lot of help!
I strongly suggest you use a UITableView or UICollectionView (which are very similar code-wise, but have a different display style).
This will be a good way to manage UX and memory because the cells are just made for that kind of things.
You can find good tutorials about this on raywenderlich or appcoda
For example this one
After this is implemented you'll wanna have a look at customs cells probably, so you can display/move/interact with them in a more... well, customized way.
That you can also find very easily on appcoda &/| raywenderlich
For example, here.
How about you use UICollectionView or UITableView. All your Images/Audio components are similar to each other. So you can use advantage of paging.
It will cost you much less memory since you'll only be consuming the memory for the images( in this case cells) that are showing.
Read a tutorial about UITableView or UICollectionView.
I'm building an application that requires a bunch of local images to be displayed in the imageview of a uitableviewcell. However, i'm having difficulty optimizing the performance of the uitableview. I've noticed two issues specifically: first, the view takes a while to load. Second, the scrolling gets laggy when new cells are displayed.
The viewDidLoad is loading in the images like this:
for (Object *object in self.objects)
{
object.thumbnail = [UIImage imageNamed:object.imageName];
}
this is obviously causing the long-load issue, but I'm not sure how else to get those images loaded. Is it a size issue? is this just a bad way of doing it?
The process of displaying the images also seems to be problematic, in other words, even after the images have been assigned to the thumbnail property, they still take too long to be drawn.
Although this is a specific case, I'm curious more generally on how apple loads images in photos so efficiently. Any insights? thanks
Whenever I find that my UI is lagging, the first thing I suspect is that I am performing some operation synchronously (on the main thread) that should be performed asynchronously (on a background thread).
I am also very curious as to how exactly Apple is achieving that performance in the photo app. I am writing an app that has similar requirements as yours right now. My current approach is to load a bunch of photos from disk into memory asynchronously as soon as the user opens my view controller, and continue to load (and remove photos) from memory - ahead of time - as the user scrolls.
Currently, I load each photo from disk asynchronously in cell for row at index path, which is pretty fast, but causes this cascading effect to happen if you scroll quickly through the table view. That is, the cell will appear empty for a moment before the photo appears.
I hope this sheds some light for you.
You may also be interested in trying SDWebImage - which includes an image cache object that has been making my life easier when dealing with local photos.
They are doing everything in the background on various detached threads most likely. This will allow for a great deal of fluidity in applications that are hosting/presenting a great deal of information. I have created a photo gallery myself in various applications, loading many photos simultaneously from different web APIs and whatnot, and by simply creating new threads and managing the allocation efficiently and accurately, you can get a very smooth interface/interaction
Well, the long-load issue is caused by this part of your code - UIImage imageNamed:, because this method caches all the images on the same thread, and also could crash the app if the memory is overloaded.
Try looking at this library - it should do what you are trying to achieve :)
http://www.cocoacontrols.com/platforms/ios/controls/ktphotobrowser
TL:DR
What technique does Apple use to make Photo.app so fast, even with large images?
Long Version
I watched Apple's WWDC 2010 video about scroll views to learn how to replicate Photo.app pagination behavior and low memory utilization (PhotoScroller Demo). It works well, but since images are loaded only when they are needed, when I try to paginate to another image, the app locks while the JPEG is being decompressed.
The same video shows a tiling technique to get better performance, but since I'm using photos taken from the camera and stored in the app, that doesn't seem feasible (having multiple copies of each photo, in different resolutions, would consume too much space - 4MB vs 27MB). Also, using iExplorer I noticed Photo.apps has only a copy of each photo (it doesn't even have a small thumbnail copy for the gallery).
What technique did Apple use to make Photos.app so fast? How can I get that same performance in my app?
I'm a bit confused if this should be here or on Programmers,
since there's no code in the question, but F.A.Q. says that algorithm
questions are part of Stackoverflow, and the tags here match it
better.
So if you just show one image fullscreen you can do this:
In the WWDC11 Session 104 - Advanced Scroll View Techniques they talk about infinite scrolling and how to do it. The basic idea is to scroll the view and after scrolling reposition the (UIImage)view inside the scroll view so it appears centered or whatever you layout constraints are.You could then load the new UIImage into the UIImageView. Since you only have one UIImageView it should be pretty low memory consuming. I am not sure about how the loading times of the images will behave though.
Maybe preload the next UIImage to the left and right to the current image and then load it into the UIImageView after reposition the scrollView can help here.
For anyone who is still looking for simply implementation of scroll view that hold lot's of images.
https://github.com/sumofighter666/ReusableScrollView
It is as simply as implementing UITableView