在Swift中一次加载所有单元格中的进度视图

时间:2015-06-22 11:08:34

标签: swift uitableview ios8 uiprogressview

我正在使用进度视图来显示下载指示。 下载成功。但是,我正在使用我在UITableViewCell中展示的5个进度视图。那个单元格,有START,PAUSE,RESUME按钮和1个进度视图。如果我单击开始按钮,任务开始启动,自动5个单元格开始加载。虽然我点击第一个单元格,但所有进度视图都会被加载。请指导我。我需要,进度视图加载了哪个单元格的START我按下了。我需要独立加载URL。请帮助我。

我的编码如下:

lazy var session : NSURLSession = {
        let config = NSURLSessionConfiguration.ephemeralSessionConfiguration()
        config.allowsCellularAccess = false
        let session = NSURLSession(configuration: config, delegate: self, delegateQueue: NSOperationQueue.mainQueue())
        return session
        }()

func URLSession(session: NSURLSession, downloadTask: NSURLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten writ: Int64, totalBytesExpectedToWrite exp: Int64) {
        println("downloaded \(100*writ/exp)")
        taskTotalBytesWritten = Int(writ)
        taskTotalBytesExpectedToWrite = Int(exp)
        percentageWritten = Float(taskTotalBytesWritten) / Float(taskTotalBytesExpectedToWrite)

        downLoadTblVw.delegate = self
        downLoadTblVw.reloadData()

    }

START BUTTON IB ACTION

var btnPos: CGPoint = sender.convertPoint(CGPointZero, toView: downLoadTblVw)
var indePath: NSIndexPath = downLoadTblVw.indexPathForRowAtPoint(btnPos)!

buttonTag = indePath.row

switch(buttonTag)
        {
        case 0:

            let s = "http://www.qdtricks.com/wp-content/uploads/2015/02/hd-wallpapers-1080p-for-mobile.png"
            let url = NSURL(string:s)!
            let req = NSMutableURLRequest(URL:url)
            let task = self.session.downloadTaskWithRequest(req)
            self.task = task

            task.resume()

            break
        default:
            println("WRONG BUTTON PRESSED")
            break
        }

的cellForRowAtIndexPath

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = downLoadTblVw.dequeueReusableCellWithIdentifier("download", forIndexPath: indexPath) as downLoadingTblVwCell

    cell.progressView.progress = percentageWritten


    return cell
}

0 个答案:

没有答案