Created
February 24, 2016 06:44
-
-
Save sigwyg/77b6a9cd8e60a4b0a9c2 to your computer and use it in GitHub Desktop.
Swiftで画像を非同期で取得するサンプル。Table View Cell内で同機種得すると、すげー重くなるので
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// set icon-image | |
let imageView = cell.viewWithTag(1) as! UIImageView | |
let imgPath = object.valueForKey("imgPath")!.description as String | |
if imgPath.isEmpty { | |
imageView.image = UIImage(named: "no_img.png") | |
} | |
else { | |
let url = NSURL(string: imgPath) | |
let requestUrl = NSURLRequest(URL: url!) | |
NSURLConnection.sendAsynchronousRequest(requestUrl, queue: NSOperationQueue.mainQueue()) { (response, data, error) -> Void in | |
if error != nil { | |
print(error) | |
} | |
else { | |
if let dlImage = UIImage(data: data!) { | |
imageView.image = dlImage | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment