I'm doing some lazy image loading for thumbnails to be displayed in a table. I have a class that loads the image for me asynchronously...but my problem (or at least, a problem) is that by the time the image loads, I have no idea whether the cell that initiated the image load even exists anymore. Is there a way for me to test to see if a particular object reference is valid before I call it?
Thanks.
Not easily or reliably. This is really more of a design problem on your part which could conceivably have many different solutions. My first inclination would be to give the loader some sort of index or hash value rather than a pointer to a live object and tell it to go find the right cell when it's done.
Related
I am trying to implement code in order to retrieve group information from my Parse cloud.
The issue comes in displaying the user images. as sometimes (I think) the image is not found yet, but the simulator tries to download it.
The code is running as following:
in viewDidLoad I use findObjectsInBackgroundWithBlock
in order to find the groupMember in class "Group" by their ids.
in viewDidAppear (which I figure is a bit behind in the timeline) findObjectsInBackgroundWithBlock to find their profile Pictures. Storing them in an Array and downloading the images in my cellForRowAtIndexPath method.
Is there a way to guarantee an outcome? Or even a better method to reach my goal?
I have a feeling the irregularity of the problem is because of the calls running in the background and not being complete before you are working on the cell.
But.... are you using a Parse PFQueryTableViewController or a UITableView?
Reason for asking is that the Parse PFQueryTableViewController provides a PFTableViewCell - and both these classes are very happy running in the background and working well together.
Now the important thing about PFTableViewCell is that if you wish to display an image in your table, then you can give it a standard image that is initially displayed to users and then in the background it can check to see if a real image exists and if it does, download and switch out the initial image.
http://blog.bizzi-body.com/2015/02/13/how-to-display-parse-com-images-in-a-table-view/
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.
I am using ASIHTTPRequest, i have to populate my table with images. So people at forums suggest to cache the image to increase the performance.
I have no clue how to do this. I will be able to do this if someone helps me with some sample code or give me a link to a tutorial that explains this well. Help
You might think this is duplicate, in fact i too found many similar questions of SO, like this, but none of these helped.
Basically, you keep a dictionary with keys being the cell # and it's object being image. Right when you are about to make a request for an image, first check if it already exists in your dictionary. If it does, simply use that, otherwise, download the image and stick it inside your dictionary.
Simply keep an array of objects that contain all of the information that you want to be shown in the table view. This array can contain objects that hold all of the information that you may need, such as pictures, whether or not the picture has been loaded, labels. Really anything you want. Just make sure that once you are done with the array though that it does get released, which is not much of an issue in iOS 5, but if you are using anything older than that, be sure to release it or at least set the array to nil after.
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 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.