I have seen many apps that load data to UITableViews from the internet, and they usually load smoothly. Now it's my turn to load in that kind of data. I am getting different data at the same time, separating categories with ~ and pieces of categories with #. This works great, and I have managed to separate the data in obj-c perfectly.
Everything in my app works, it's just that the loading takes a lot of time.
So, I guess the real question is, how can you load in data for a tableView in the background, showing a label/UIActivityView or something while it is loading?
Thank you.
The simplest way is to add a temporary cell which shows some kind of loading progress (label with 'Loading...' text, or a UIActivityIndicator, etc). When your data is done loading, remove that cell and add your actual cells with your data.
To load data 'in the background' I would recommend having a look at NSURLConnection. It lets you implicitly load the data asynchronously so you don't have to deal with threads.
I am not getting your question clearly. Why don't you use UIActivityIndicator to show the loading. You can do it from your nib or programmatically.
One ting is also possible that you can load the contents From intenet by using NSXMlParsing which will be much quiker and show an activity indiacator until all date gets parsed and filling the table entirely at once.
Do reply if you get this.
Related
I am newly in iOS development.I have to make an application for a car dealer in which i have to show different cars with different colors.Please tell me the best way because i have to fetch lots of images every time from the web server.How can i reduce the rendering time in fetching the images.
Please consider i am very new in ios development and need your help.
If you have any sample application please share it with me.
You can use DB to store images as BLOB and also fetch images only when there is update at server.
First, make sure you send images that are no larger than needed.
If you have a list view that shows pictures of the cars, have a webservice send you premade thumbnails that are (preferably) exactly the right size.
Second, Make sure the images are loaded separately from the data set.
The best place to do this, would be in the controllers for your UITableViewCell.
Just have your UITableViewCell start their own thread to download and display the image as soon as they come into view.
Third; caching.
Make sure you save local copies of the thumbnails, and make sure the Table View Cells search for local copies of the images, and load those instead of downloading them if they are already locally present.
you can do:-
use lazy loading
use paging
use predicates for searches
use fast enumeration
these things in general will keep your app smooth
If you are going to show images in UITableView then you can use lazy loading. It will load images only for the displayed rows and once image for any row index has been downloaded, it will not repeat downloading for that row index. So its faster and useful.
I'm encountering a common TableView data reloading problem. I've read many questions on the same subject but the problem was never exactly the same as mine...
I have a navigation based application. In the RootViewController's viewDidLoad method I make a request in order to get JSON data (articles). When the connection has finished loading I create custom Article objects for each entry. The Article class has an initWithDictionnary method which initializes the attributes of the object and most importantly creates a request to download an image. When the connection has finished loading I set the image attribute of the Article object.
The goal is to initialize the cell.imageView.image property with the downloaded image. At that point, you may have guessed what the problem is about.
Images are downloaded after the cell image is rendered so it stays empty until the cell is reloaded (if it gets out of the screen and then back in for example).
I guess I should call reloadData at a certain time but I don't know when. Ideally I would call it when all the cells are loaded but it doesn't seem possible.
I've tried a bunch of crazy things like waiting for a cell to load and the try to reload the previous one but it didn't work.
By reading Q&A out here I learned about Apple's LazyTableImage sample code but I don't understand all of it so I'm not sure I should/could use it.
Please ask me if you need more details.
Thanks in advance for any help.
You have to load the images Asynchronously. Keep in mind that your table data should contain a field per row specifying if the image was loaded so that (if true) you can skip loading and just display cached images.
Look at this question first: Load images async
There are about 10 good Lazy Loading Image UITableView tutorials. Pick one.
You'll get the hang of it by reviewing the tutorials after a while. Stick with it, it's an important concept, not only for this project, but for the rest of your programming career.
Lazy Loading Image UITableView Tutorials that'll make you smarter!
I have a table which is made from custom UITableViewCells which contains downloaded images.
Ive found the app crashes after too many images are displayed. How can best stop this? I don't mind deleting the first images, but don't know of the best way to do it.
EDIT
How do I write the images to the device for caching?
Post your cellForRowAtIndexPath code. Sounds like you have a problem there. If you're certain you do not, then when you receive the memory warning, release any objects you do not need, and can easily be loaded again if required. These objects may be in other ViewControllers not on screen or ImageView objects already displayed.
Best we can do unless you post code.
Or read Apple's Memory Management Guide.
I am building an app with several UIViews which are generated dynamically, based on user inputs. These UIViews may contain labels, images and text. They take some time to generate so I would like the user to be able to load them up quickly on future launches of the app without having to redraw them again. One requirement is that they need to keep their interactive state so the user can continue to edit them.
I looked into NSKeyedArchiver but this doesn't seem to support UIImage. Also, I can't save it as PNG since I would like to retain their interactive state.
Is there any way to do this?
You should consider keeping the model of your data separate from the interface. You can then use this stored model to generate the interface. I know you specifically said that you don't want to do this. However, any built in method is going to have to rebuild the UIViews in exactly the same way.
If the processing of the model data is the issue, try to come up with a way to efficiently represent the state of the interface so that you don't have to start from scratch. However, that will be a lot more work.
I have a table view with all cells having the UITableViewCellStyleSubtitle,
the images of all the cells are got from the server.
However, those images are not changed frequently.
Someone can show me how to improve the user experience? Each time, user scroll down the table, it seems that it goes online to check and download images again.
Or at least, show me some options that are available to achieve the goal.
Thanks,
The Three20 library has an ImageView subclass that accepts a URL to your remote image and uses the excellent TTURLRequest/Caching mechanism to fetch images. It maintains an in-memory and on-disk cache and will only download images if they are not cached or have expired. You can configure the default cache-expiration time or use a value from your HTTP response. If you use the TTTableViewController subclass and the appropriate TTTableItem subclass, you will get the appropriate image downloading behavior for free. However, it is not necessary to use every three component to do what you need. If you're integrating into existing code, you could create your own UITableViewCell subclass that uses a TTImageView instead of the standard UIImageView. Then, in your cell configuration methods, you can set a default placeholder image and a URL to load and it will pretty much take care of the rest. As a performance optimization, you should also implement the UIScrollView delegate methods in your tableview controller to suspend the TTURLRequestQueue during scrolling (take a look at the TTTableViewController to see how this is done).
You could try one of the following
Create an dictionary and cache all the fetched images in it using the image name as the key
Cache and reuse the entire UITableView cells in tableView:cellForRowAtIndexPath:
If it is just one image repeating load it one outside tableView:cellForRowAtIndexPath:
You write that the images change on a monthly basis - you could save the images to disk as they are used and just either check if the images have changed on the back burner or at a given daily interval redownload the images. Brian Chapados reply seems interesting .
Depending on your code there is probably a ton of other ways to improve image loading. Hope that helps...