Skip to content

Instantly share code, notes, and snippets.

@rschmukler
Created June 5, 2014 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rschmukler/c401a33fbe4afb254393 to your computer and use it in GitHub Desktop.
Save rschmukler/c401a33fbe4afb254393 to your computer and use it in GitHub Desktop.
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
let kCellName = "SearchResults"
var cell: UITableViewCell? // allow nil value for cell
cell = tableView.dequeueReusableCellWithIdentifier(kCellName) as? UITableViewCell // allow for nil value on first lookup
if(cell == nil) {
cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: kCellName)
}
var rowData: NSDictionary = self.tableData[indexPath.row] as NSDictionary
cell!.text = rowData["trackName"] as String // force a value (or throw a runtime error with "!")
// Get Album Artwork
var urlString: String = rowData["artworkUrl60"] as String
var imgURL: NSURL = NSURL(string: urlString)
var imgData: NSData = NSData(contentsOfURL: imgURL)
cell!.image = UIImage(data: imgData)
var formattedPrice: NSString = rowData["formattedPrice"] as NSString
cell!.detailTextLabel.text = formattedPrice
return cell
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment