0

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 &lt Foundation/Foundation.h &gt
// declare protocol to accept progress status of file downloads
@protocol FileDownloaderDelegate &lt NSObject &gt
// 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 &lt FileDownloaderDelegate &gt delegate;  // to send progess value to UI
}

@property (nonatomic, retain) NSOperationQueue *operationQueue;
@property (nonatomic, assign) id &lt FileDownloaderDelegate &gt 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  &lt UIKit/UIKit.h &gt
#import &lt FileDownloader.h &gt
@interface MyTableViewCell : UITableViewCell &lt FileDownloaderDelegate &gt {
 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.

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
tmin
  • 1
  • 2

1 Answers1

0

Your +sharedInstance method returns a ContentSyncer*, not a FileDownloader*. That may be the cause of the setDelegate: not found warning.

Also, you can and should define your FileDownloaderDelegate protocol in FileDownloader.h. Import this header file in MyTableViewCell.h, but use quotes instead of angel brackets. E.g.,

#import "FileDownloader.h"
Darren
  • 25,520
  • 5
  • 61
  • 71
  • Thanks for the reply. The ContentSyncer was a left-over when I renamed the classes to make the code easier to read for posting here. I reedited the code. The code is compiled after I separated out the protocol declaration to a separate file according to a suggestion from here. http://stackoverflow.com/questions/1233371/how-to-conform-to-a-self-made-protocol I read somewhere that there might be some "circular imports". But I don't know where that happen. Now I can get updates from the UI's tableCell. The only thing left is compiler warning when I assign the delegate. Thansk! – tmin Dec 15 '09 at 05:34