委托未正确设置

时间:2014-06-26 02:40:07

标签: ios iphone inheritance delegates delegation

我正在处理一个项目,我的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

{

1 个答案:

答案 0 :(得分:1)

假设您的代码在ARC下,我从代码中了解到DownloadTableView *download是一个局部变量。因此,DownloadTableView对象在声明结束的方法范围之后被释放。因此,委托方法不会被调用,因为委托被释放。为避免这种情况,您可以将DownloadTableView对象创建为实例变量。

相关问题