【发布时间】:2014-08-16 18:41:01
【问题描述】:
我正在做一个项目,我的 UIWebview 类需要从我的 DownloadView 类中执行一个方法
我正在使用开源项目https://github.com/robertmryan/download-manager
当这段代码执行方法时:
DownloadTableView *download = [[DownloadTableView alloc] init];
[download queueAndStartDownloads:_downloadURL];
此行没有设置代理权限
self.downloadManager = [[DownloadManager alloc] initWithDelegate:self];
全启动下载方法
- (void)queueAndStartDownloads:(NSURL *)url
{
NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString *downloadFolder = [documentsPath stringByAppendingPathComponent:@"downloads"];
if ([[NSFileManager defaultManager] fileExistsAtPath:downloadFolder]) //Does file exist?
{
if (![[NSFileManager defaultManager] createDirectoryAtPath:downloadFolder
withIntermediateDirectories:NO
attributes:nil
error:nil]) {
}
}
self.downloadManager = [[DownloadManager alloc] initWithDelegate:self];
self.downloadManager.maxConcurrentDownloads = 4;
NSString *downloadFilename = [downloadFolder stringByAppendingPathComponent:[url lastPathComponent]];
[self.downloadManager addDownloadWithFilename:downloadFilename URL:url];
self.cancelButton.enabled = YES;
self.startDate = [NSDate date];
NSLog(@"DOwnling");
[self.downloadManager start];
}
我的 DownloadView 类中的方法不会执行
- (void)didFinishLoadingAllForManager:(DownloadManager *)downloadManager
{
【问题讨论】:
-
您没有显示足够的代码来确定问题所在。但是一般不要做“initWithDelegate”方法,这不是通常的做事方式。为您的类(或子类)使用指定的初始化程序,然后分配委托。
-
我正在使用这家伙下载管理器github.com/robertmryan/download-manager
-
如果需要委托,那么我认为指定的初始化程序 initWithDelegate 没有任何问题。
-
当然,您完全可以忽略约定。但是,如果您想与他人合作,像 Apple 和其他人一样做这些事情会有所帮助。
-
“没有设置代理权”对您意味着什么?你期望会发生什么?您观察到什么让您感到惊讶?
标签: ios iphone inheritance delegates delegation