I think that the best solution for your problem would be to create a custom delegate
protocol that the DetailViewController
and the VideoListController
can use to communicate with each other. Check this post for additional information How to use custom delegates in Objective-C
In a nutshell the strategy is the following:
1. The DetailViewController
defines a delegate
protocol
that it uses to pass events to its delegate
2. The VideoListController
becomes the delegate to that it knows whenever an upload has progressed or been completed
3. The VideoListController
keeps track of which DetailViewController
s have completed the download
Here is come code:
DetailViewController.h
:
@class DetailViewController;
@protocol Delegate <NSObject>
- (void) detailViewController: (DetailViewController *) theDetailViewController didFinishDownloadingVideoWithResults:(BOOL)successful;
@end
@property (nonatomic, weak) id<DetailViewController> delegate;
DetailViewController.m
:
Whenever a download is complete do the following:
if ([[self delegate] respondsToSelector:@selector(detailViewController:didFinishDownloadingVideoWithResults:)]){
[[self delegate] detailViewController:self didFinishDownloadingVideoWithResults:YES];
}
Now, in the VideoListController.m
make sure you establish yourself as the delegate of the DetailViewController
.
[theDetailViewController setDelegate:self];
And implement the delegate method. You can for instance have a dictionary that defines which DetailViewControllers have completed the download:
- (void) detailViewController: (DetailViewController *) theDetailViewController didFinishDownloadingVideoWithResults:(BOOL)successful{
detailViewControllersDownloadInformation[theDetailViewController] = @(successful);
}
Now, whenever you need to check if a DetailViewController
did indeed complete a download, all you have to do is check that dictionary
if (detailViewControllersDownloadInformation[theDetailViewController] && detailViewControllersDownloadInformation[theDetailViewController] == @(YES)){
// Did download a video
}
Keep in mind that the solution I provide will only let you know if the download has been completed. If you also want to keep track of the progress you need to pass that as an additional parameter in the delegate. We are also assuming that you keep all of the DetailViewController
s in memory. If you release and reuse them you will need to keep track of which element was downloaded in a different data structure.