2014-08-29 64 views
0

我想重新加载我的tableView内块,但我的插座总是零。我有一个带有小弹出窗口的背景下载管理器来显示当前的下载。一切工作正常,但我无法重新加载我的tableView下载时(例如显示下载速度)。用addOperationWithBlock重新加载TableView

我有我的UITableView

class FileDownloadHandlerViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, NSURLSessionDelegate, NSURLSessionDownloadDelegate { 

    @IBOutlet var fileDownloadTable: UITableView! 

的简单出口//这是我的下载任务

func URLSession(session: NSURLSession!, downloadTask: NSURLSessionDownloadTask!, didFinishDownloadingToURL location: NSURL!) { 

.... 

if(success == true) { 

     // Change the flag values of the respective FileDownloadInfo object 

     let index:Int = self.getFileDownloadInfoIndexWithTaskIdentifier(downloadTask.taskIdentifier) 

     let fdi = arrFileDownloadData.objectAtIndex(index) as FileDownloadInfo 

     fdi.isDownloading = false 
     fdi.downloadComplete = true 
     fdi.taskIdentifier = -1 
     fdi.taskResumeData = nil 

     // Reload the respective table view row using the main thread. 

     let indexPath = NSIndexPath(forRow: index, inSection: 0) 

     println(indexPath) 

     if(fileDownloadTable == nil) 
     { 
      println("still nil") 
     } 

     NSOperationQueue.mainQueue().addOperationWithBlock({ 

      if(self.fileDownloadTable == nil) 
      { 
       println("nil again") 
      } 

//This is the Problem. fileDownloadTable is always nil 


      //self.fileDownloadTable.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.None) 

     }) 

    } else { 

     println("Unable to copy temp file. Error: \(error)") 

    } 

什么想法?我需要将我的奥特莱斯通过此块吗?如果我使用这个不在弹出窗口内的DownloadController(所以仍然是我的mainViewController)一切正常。

在此先感谢。

编辑

好发现的问题是,我必NSUrlSessionConfiguration作为我FileDownloadClass之外的全局变量。

var session:NSURLSession! 
var sessionConfiguration:NSURLSessionConfiguration = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier("com.company") 

如果我在我的课上设置它,我可以重新加载tableView。但是,现在我得到关闭我的popover后,并加载别的以下错误:

带标识符的后台URLSession ...已存在!

如何检查是否已有URLSession,或将其设置为全局URLSession?

在viewDidLoad中
+0

尝试:fileDownloadTable.reloadData() – 2014-08-29 23:09:02

+0

fielDownloadTable为零,所以无论doesent如果重装全部或只是一个特定细胞。 – derdida 2014-08-29 23:11:59

+0

就这样我很清楚:你的'URLSession'函数是在你的下载管理器中定义的,而不是在'FileDownloadHandlerViewController'中,对吧? – 2014-08-30 00:30:59

回答

0

,加

[self backgroundSession]; 

然后添加这一功能,因为它是

- (NSURLSession *)backgroundSession 
    { 
     static NSURLSession *session = nil; 
     static dispatch_once_t onceToken; 
     dispatch_once(&onceToken, ^{ 
      NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"com.iosDevelopment.VDownloader.SimpleBackgroundTransfer.BackgroundSession"]; 
      session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil]; 
     }); 

    return session; 
} 
+0

有关更多详细信息,请访问https://github.com/mzeeshanid/MZDownloadManager – 2014-12-23 07:11:23

相关问题