In my xcode app, I previously had things set up like this:
main display -> table of episodes view -> episode detail view
When the user selected an episode in the UITableView, the detail view was loaded. The detail view then gave some new functions, such as downloading the corresponding file. This download was handled through a helper class I made and initiated when the user hit a button on the detail view.That all worked fine.
But because there really wasn’t too much new information in the detail view, I started trying to bring it all into the cell on the table view. Now when a user clicks a cell, the cell height expands and displays the extra information.
So my question is this. How do I handle the methods I used to call from the detail view, like to download the file?
For example, the function I was using to download the associated file:
- (IBAction)downloadTheFile:(id)sender {
self.downloadProgress.hidden = false;
self.downloadButton.hidden=true;
[self.myEpisodeDownloader getFileFromURL:[self.currentEpisode epFileURL] withIndicator:[self downloadProgress]];
}
When I try to bring that over into the new method, I get confused about what to pass to it and how it accesses different things. Basically, in losing the “detail view” I have lost a container for everything. You can see in my function I use “self” to get and modify different things. Now instead of a container I have instances of cellForRowAtIndexPath trying to do things.
I started down the path of passing everything to the download function, but it started to smell wrong. Should I try delegates? An intermediary class? Give up and go back to the old way?
Your Cell becomes the new container, you can probably move a lot of the code you had in your detailview straight into a subclass of
UITableViewCell. If you have not subclassedUITableViewCellfor your cell you will probably need to, while you can accomplish everything from the outside, things will be a lot better separated and clearer if you accomplish them in a subclass.In that subclass you should be able to pretty much do that same things that you did in your tableview, you probably eventually will want to prevent the user for just tapping a large number of cell to set off the downloads or queue them, but that is something you should be able to ingore in the first step.
UITableViewDelegateprovides a functiontableView:-[did|will]selectRowAtIndexPath:you can use that to find the instance of the cell that has been selected, and trigger the download process for that cell, if necessary. Any view updates you accomplish from the inside you custom cell.