I am trying to update the multiple file download progress value to UIProgressView on a table cell. I have the FileDownloader class which has NSOperationQueue that does asynchronous download operations. I am thinking to update the UI using a "delegate" from FileDownloader class. But I cannot compile the codes. I have FileDownloader as Singleton. I am wondering whether I am missing to understand something fundamental.
The following is the setup of the code.
FileDownloader.h
#import < Foundation/Foundation.h >
// declare protocol to accept progress status of file downloads
@protocol FileDownloaderDelegate < NSObject >
// this function will update the progressview and re-display the cell
- (void) updateProgessWithCurrentValue:(NSNumber*)value totalValue:(NSNumber*)totalValue;
@end
@interface FileDownloader : NSObject {
NSOperationQueue *operationQueue; // for file download operations
id < FileDownloaderDelegate > delegate; // to send progess value to UI
}
@property (nonatomic, retain) NSOperationQueue *operationQueue;
@property (nonatomic, assign) id < FileDownloaderDelegate > delegate;
+(FileDownloader*) sharedInstance; // FileDownloader is Singleton with its standard methods
// when download is progressing, the delegate function will be called like
// [self.delegate updateProgessWithCurrentValue:10 totalValue:100];
//
@end
MyTableViewCell.h
#import < UIKit/UIKit.h >
#import < FileDownloader.h >
@interface MyTableViewCell : UITableViewCell < FileDownloaderDelegate > {
UIProgressView *progressView;
}
@property (nonatomic, retain) UIProgressView *progressView;
// MyTableViewCell.m will have the implementation of
// - (void) updateProgessWithCurrentValue:(NSNumber*)value totalValue:(NSNumber*)totalValue;
// to update UI
@end
First, I got "cannot find protocol declaration for FileDownloaderDelegate" compiler error in MyTableViewCell. So I moved out the protocol declaration of FileDownloaderDelegate to a separate .h file to be able to compile. Even then, I still cannot assign to the delegate from my tableViewController using
[[FileDownloader sharedInstance] setDelegate:myTableViewCell];
I got the "FileDownloader may not respond to setDelegate method" warning, meaning it does not know the delegate (although I have "@synthesize delegate"). I am wondering whether I am not understanding something about singleton or delegate usage.