Saving images then displaying them in a table - iphone

Can anyone point me towards an example or tutorial for this? I basically want to save images to the documents folder then have a table that contains them for user review later on.
I've got it working but only when I go and add each image to an array then generate the table with contents of said array first. Is there a quicker or more automated way to do this?

Here's a nice tutorial giving a project you could adapt:
http://www.raywenderlich.com/19788/how-to-use-nsoperations-and-nsoperationqueues
While it's actually about doing lazy loading and other image operations on a secondary thread (keeping your UI responsive) you may as well display images in a table this way to begin with.
The main modification you would make is to look for the locally stored image first, then go and do the network fetch if it is not available. A further refinement would be to check a timestamp stored with each local image and update from the web if a newer one was available.

That is correct, you prepare your datasource first (which is array of images), then you pass it to tableview and reload it. If you are working with lots of images, consider lazy loading.
Apple has an example on this.

Related

How to create an application which uses bulk of images from web service

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.

iPhone : UITableView reloadData timing problem

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!

Saving a UIView for next launch (not as an image)

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.

UITableView - Loading data from internet

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.

How to load images from server to tableView efficiently?

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...