Loading progress view in all cell at a time in Swift

692 views Asked by At

I am using progress view to display download indication. Downloading successfully. But, I am using 5 progress view which I have showed in UITableViewCell. That cell, having START, PAUSE, RESUME buttons and 1 progress view. If I click start button, task getting initiating, automatically 5 cells get starts to load. Though I am clicking first cell, all progress view gets loaded. Kindly, guide me. I need, progress view gets loaded for which cell's START I pressed. I need to load URL independently. Kindly help me.

My Coding below:

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

There are 0 answers