UITableViewCellに画像を非同期で読み込みたいのですが、下のコードを実行すると、セルをタップした時にセルを再利用する前の画像から新しい画像に切り替わる、という結果になってしまいます。
どうすれば、セルをタップしなくても新しい画像に切り替わりますか?
よろしくお願いします。
Swift
1let url = "http://example.com" 2let config = NSURLSessionConfiguration.defaultSessionConfiguration() 3let session = NSURLSession(configuration: config) 4let req = NSURLRequest(URL: url) 5let task = session.dataTaskWithRequest(req, completionHandler: { 6 (data, resp, err) in 7 let imageData = UIImage(data: data!) 8 cell.iconImage?.image = imageData 9}) 10task.resume()
コンソールに出てきた内容です↓
This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future release. Stack:( 0 CoreFoundation 0x00000001816ad918 <redacted> + 148 1 libobjc.A.dylib 0x0000000180d1bf80 objc_exception_throw + 56 2 CoreFoundation 0x00000001816ad848 <redacted> + 0 3 Foundation 0x000000018214b2d4 <redacted> + 88 4 Foundation 0x0000000181fd199c <redacted> + 56 5 Foundation 0x0000000181fcd55c <redacted> + 260 6 UIKit 0x00000001864a75e0 <redacted> + 64 7 UIKit 0x00000001864a80f8 <redacted> + 244 8 UIKit 0x00000001869db9d0 <redacted> + 200 9 UIKit 0x0000000186c118b4 <redacted> + 268 10 UIKit 0x00000001866aefac <redacted> + 176 11 UIKit 0x000000018639b778 <redacted> + 656 12 QuartzCore 0x0000000183daab2c <redacted> + 148 13 QuartzCore 0x0000000183da5738 <redacted> + 292 14 QuartzCore 0x0000000183da55f8 <redacted> + 32 15 QuartzCore 0x0000000183da4c94 <redacted> + 252 16 QuartzCore 0x0000000183da49dc <redacted> + 512 17 QuartzCore 0x0000000183dd3ae0 <redacted> + 236 18 libsystem_pthread.dylib 0x00000001813161e0 <redacted> + 584 19 libsystem_pthread.dylib 0x0000000181315d58 <redacted> + 136 20 libsystem_pthread.dylib 0x000000018131553c pthread_mutex_lock + 0 21 libsystem_pthread.dylib 0x0000000181315020 start_wqthread + 4 )
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2016/03/05 04:19
2016/03/05 05:26
退会済みユーザー
2016/03/05 07:16
2016/03/08 09:21