Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
- var cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as UITableViewCell
- if cell == nil {
- cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: kCellIdentifier)
- }
- var rowData: NSDictionary = self.tableData[indexPath.row] as NSDictionary
- // Add a check to make sure this exists
- let cellText: String? = rowData["trackName"] as? String
- cell.text = cellText
- var urlString: NSString = rowData["artworkUrl60"] as NSString
- var image: UIImage? = self.imageCache.valueForKey(urlString) as? UIImage
- if (!image?) {
- cell.image = UIImage(named: "Blank52")
- dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
- // If the image does not exist, we need to download it
- var imgURL: NSURL = NSURL(string: urlString)
- // Download an NSData representation of the image at the URL
- var request: NSURLRequest = NSURLRequest(URL: imgURL)
- var urlConnection: NSURLConnection = NSURLConnection(request: request, delegate: self)
- NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: {(response: NSURLResponse!,data: NSData!,error: NSError!) -> Void in
- if !error? {
- //var imgData: NSData = NSData(contentsOfURL: imgURL)
- image = UIImage(data: data)
- // Store the image in to our cache
- self.imageCache.setValue(image, forKey: urlString)
- cell.image = image
- }
- else {
- println("Error: \(error.localizedDescription)")
- }
- })
- })
- } else {
- cell.image = image!
- }
- // Get the formatted price string for display in the subtitle
- var formattedPrice: NSString = rowData["formattedPrice"] as NSString
- cell.detailTextLabel.text = formattedPrice
- return cell
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement