2014-06-26 44 views
0

進出口工作的一個項目,我的一個UIWebView類需要代表沒有被正確設置

我使用的是開源項目https://github.com/robertmryan/download-manager

當這個代碼執行的方法,從我DownloadView類執行的方法:

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

你還沒有顯示足夠的代碼來查明問題。但通常不要做一個「initWithDelegate」方法,它不是通常的做事方式。爲您的類(或子類)使用指定的初始化程序並在此之後分配委託。 –

+0

我正在使用這個傢伙下載管理器https://github.com/robertmryan/download-manager – nickivey

+0

如果需要委託,那麼我看到指定的初始化程序initWithDelegate沒有錯。 – CrimsonChris

回答

1

假設你的代碼是ARC下,從代碼我明白DownloadTableView *download是一個局部變量。因此,DownloadTableView對象在聲明方法的作用域結束後被釋放。因此委託方法不會被調用,因爲委託被釋放。爲了避免這種情況,您可以創建DownloadTableView對象作爲實例變量。

+0

感謝您的建議,但表格視圖仍然不更新任何想法爲什麼? – nickivey

+0

你在調用reloadData嗎? –