I am creating a real estate app. I have a screen which displays a listing of all entries with a thumbnail and a little text on the side. These I have loaded from the server when the app launched. Each entry can have up to 5 photos, which I do not pre-load for obvious reasons. My issue is this… when the user selects an entry, the app downloads the larger photos from the server. Depending on circumstances this can take a few seconds. Right now the app just hangs for those few seconds. I don’t know of any practical way to use an activity indicator in a list. A header space just seems like wasted space to use only to display”Loading…”. Anyone have any ideas on what I can do to let the user know that loading is in progress?
Clarification: Once an entry is selected from the list, I load up another Table View Controller which has the photos in its list of selections. I currently load the photos in the ViewDidLoad using
NSData *myPhoto = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:myURL]];
You can:
Use
UIActivityIndicatorViewto show a spinning activity indicator in the precise spot where the image will eventually be loaded.In a separate queue download the image. While the below code uses GCD, it’s actually much better to use
NSOperationQueuebecause on a slow network, using GCD can consume all of the available worker threads, detrimentally affecting performance on the app. ANSOperationQueuewith a reasonablemaxConcurrentOperationCount(such as 4 or 5) is much better.When the download is complete, dispatch the updating of the UI back to the main queue (e.g. turn off the activity indicator and set the image).
This is sample code from a gallery app that shows how you might do it. This is probably more complicated than you need and might be hard to repurpose via cut-and-paste, but the
loadImagemethod shows the basic elements of the solution.By the way, if the image you’re downloading is in a
UIImageViewin aUITableViewCellthe final update back to the table might want to do something about checking to see if the cell is still on screen (to make sure it wasn’t dequeued because theUITableViewCellscrolled off the screen). In that case, the final UI update after successful download of the image might do something like:Note, this is using the
UITableViewmethodcellForRowAtIndexPath, which should not be confused with theUITableViewControllermethodtableView:cellForRowAtIndexPath.