をダウンロードしてください。これは私の問題です:URLから画像を非同期でダウンロードしますが、TableViewをすばやくスクロールすると画像が回転し始めます(正しい画像が表示されるまで画像が交互に表示されます)。スウィフト画像私はスウィフトでテーブルビューで非同期に画像をダウンロードして問題を解決しようとしているテーブルビュー
これは私のダウンロード非同期コードとのImageCache
let imageCache = NSCache()
//DOWNLOAD Image ASINC
extension UIImageView {
public func imageFromServerURL(url: String){
if(imageCache.objectForKey(url) != nil){
self.image = imageCache.objectForKey(url) as? UIImage
}else{
let sessionConfig = NSURLSessionConfiguration.defaultSessionConfiguration()
let session = NSURLSession(configuration: sessionConfig, delegate: nil, delegateQueue: nil)
let task = session.dataTaskWithURL(NSURL(string: url)!, completionHandler: { (data, response, error) -> Void in
if error == nil {
dispatch_async(dispatch_get_main_queue(), {() -> Void in
if let downloadedImage = UIImage(data: data!) {
imageCache.setObject(downloadedImage, forKey: url)
self.image = downloadedImage
}
})
}
else {
print(error)
}
})
task.resume()
}
}
}
と私はテーブルビューでリコールです:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("record_charts", forIndexPath: indexPath) as! myTableViewCell
let url_img = "https://image/download.jpg"
cell.immagine.imageFromServerURL(url_img)
return cell
}
チェックこの質問:https://stackoverflow.com/questions/15668160/asynchronous-downloading-of-images-for-uitableview-with-gcd。 –
あなたはあなたの問題は、その質問からある場所の一般的なアイデアを得ることができ – mfiore
...これは、オブジェクト-Cであり、それは動作しません。 –