下载mp3文件的方法有效,打印出的百分比也有效,但我想能够更改标签,我不会工作所有发生的是文件下载,同时打印出下载的百分比但不是当试图改变标签时。我究竟做错了什么?
func download_Songs(){
var request = HTTPTask()
let downloadTask = request.download(urlText, parameters: nil, progress: {(complete: Double) in
var a:String = String(format: "%f", complete)
self.PlaySong.titleLabel?.text = a
println("percent complete: \(a)")
}, success: {(response: HTTPResponse) in
println("download finished!")
if response.responseObject != nil {
//we MUST copy the file from its temp location to a permanent location.
if let url = response.responseObject as? NSURL {
if let path = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first as? String {
if let fileName = response.suggestedFilename {
if let newPath = NSURL(fileURLWithPath: "\(path)/\(fileName)") {
let fileManager = NSFileManager.defaultManager()
fileManager.removeItemAtURL(newPath, error: nil)
fileManager.moveItemAtURL(url, toURL: newPath, error:nil)
}
}
}
}
}
} ,failure: {(error: NSError, response: HTTPResponse?) in
println("failure")
})
}
答案 0 :(得分:0)
NSURLConnectionDataDelegate是您应该寻找的