Cocoa touch 要更新UIProgressView以下载多个文件(如何使用委托)?

Cocoa touch 要更新UIProgressView以下载多个文件(如何使用委托)?,cocoa-touch,download,singleton,delegates,uiprogressview,Cocoa Touch,Download,Singleton,Delegates,Uiprogressview,我正在尝试将多文件下载进度值更新为表单元格上的UIProgressView。我有一个FileDownloader类,它具有执行异步下载操作的NSOperationQueue。我正在考虑使用FileDownloader类中的“委托”更新UI。但是我不能编译代码。我有文件下载器作为Singleton。我想知道我是否错过了一些基本的东西 下面是代码的设置 文件下载程序 #import < Foundation/Foundation.h > // declare protocol to acce

我正在尝试将多文件下载进度值更新为表单元格上的UIProgressView。我有一个FileDownloader类,它具有执行异步下载操作的NSOperationQueue。我正在考虑使用FileDownloader类中的“委托”更新UI。但是我不能编译代码。我有文件下载器作为Singleton。我想知道我是否错过了一些基本的东西

下面是代码的设置

文件下载程序

#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 
首先,我在MyTableViewCell中发现“找不到FileDownloaderDelegate的协议声明”编译器错误。因此,我将FileDownloaderDelegate的协议声明移出到一个单独的.h文件中,以便能够编译。即使如此,我仍然无法使用从tableViewController分配给代理

[[FileDownloader sharedInstance]setDelegate:myTableViewCell]


我得到了“文件下载程序可能不响应setDelegate方法””警告,这意味着它不知道该委托(尽管我有“@synthesis delegate”)。我想知道我是否不了解singleton或委派用法。

您的
+sharedInstance
方法返回的是
ContentSyncer*
,而不是
文件下载器*
。这可能是出现
setDelegate:notfound
警告的原因

此外,您可以而且应该在FileDownloader.h中定义您的FileDownloaderDelegate协议。在MyTableViewCell.h中导入此头文件,但使用引号而不是尖括号。例如:

#import "FileDownloader.h"

谢谢你的回复。ContentSyncer是我重命名这些类以使代码更易于阅读以便发布到这里时留下的。我重新编辑了密码。代码是在我根据这里的建议将协议声明分离到一个单独的文件后编译的。我在某处读到可能有一些“循环进口”。但我不知道发生在哪里。现在我可以从UI的tableCell获取更新。唯一剩下的就是当我分配委托时编译器发出警告。坦斯克!