I am having trouble with a UITableView and segueing from it. The table view contains a list of places, and when a cell is clicked it segues to a list of photos from that place. It takes a bit of time to load the info for those photos, so it sticks on the list of places for a bit. My problem is that I don’t want to freeze the user out of the app while it’s loading, and if the user decides to switch the place they want, I want them to be able to. Is there a simple solution for this, or would it require a redesign? Here’s what’s called when the cell is clicked:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[self.activityIndicator startAnimating];
[[tableView cellForRowAtIndexPath:indexPath] setAccessoryView:self.activityIndicator];
self.query = ^{return [FlickrFetcher photosInPlace:self.locationDataArray[indexPath.row] maxResults:50];};
self.locationSelected = [[self.locationDataArray[indexPath.row] valueForKeyPath:@"_content"] componentsSeparatedByString:@","][0];
[self performSelector:@selector(pushView:) withObject:tableView afterDelay:0.0]; // Allows spinner to start spinning before the segue is actually performed.
}
- (void)pushView:(UITableView *)tableView {
[self performSegueWithIdentifier:@"Display Image List" sender:self];
}
I’ve tried dispatching performSegueWithIdentifire:sender: to the main queue, but no luck (I didn’t think it would work, anyway). Query is what’s executed by the destination view controller. Any ideas on how to get it to work?
I think, you should perform the segue of course on the main thread (no dispatching), and load a new (empty) tableview with activityIndicator started in its cells. The fetching of images would be dispatched in the viewDidLoad method, and ‘notify’ the view, if the loading has finished, and reload the tableView.
Like in this tutorial (a simple NSInvocationOperation is used to run the downloading o the background):
http://www.icodeblog.com/2010/03/04/iphone-coding-turbo-charging-your-apps-with-nsoperation/
Good luck!