-
-
Save MaxHasADHD/ece797ebe14d777b27f4 to your computer and use it in GitHub Desktop.
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
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { | |
let cell = tableView.dequeueReusableCellWithIdentifier("PopularShowCell", forIndexPath: indexPath) as! PopularShowTableViewCell | |
// Configure the cell... | |
configureCell(cell, indexPath: indexPath) | |
return cell | |
} | |
func configureCell(cell: PopularShowTableViewCell, indexPath: NSIndexPath) { | |
if segmentedControl.selectedSegmentIndex == 0 { | |
let show = popularShowsResultsController.objectAtIndexPath(indexPath) as! TVPopularShow | |
cell.titleLabel?.text = show.title | |
cell.delegate = self | |
let traktID = show.idTrakt | |
let showAlreadySaved = showIDs.indexOf(traktID.integerValue) != nil | |
let showDownloading = showsDownloading.indexOf(traktID.integerValue) != nil | |
let isWatching = showAlreadySaved || showDownloading | |
cell.isWatching = isWatching | |
// Accessibility | |
cell.accessibilityLabel = "\(show.title)" | |
cell.accessibilityValue = isWatching ? NSLocalizedString("ACCESSIBILITY_VALUE_TRACKING", comment: "Tracking") : NSLocalizedString("ACCESSIBILITY_VALUE_NOT_TRACKING", comment: "Not tracking") | |
cell.accessibilityHint = NSLocalizedString("ACCESSIBILITY_HINT_SHOW_INFORMATION", comment: "Double tap to view show information") | |
// Image | |
ImageManager.sharedManager.getImageForShow(show, completionHandler: { (image) -> Void in | |
if self.popularIndexPathsForFadedInImages.indexOf(indexPath) == nil { | |
self.popularIndexPathsForFadedInImages.append(indexPath) | |
if let fetchCell = self.tableView.cellForRowAtIndexPath(indexPath) as? PopularShowTableViewCell { | |
func fadeInImage() { | |
// Fade in image | |
fetchCell.backgroundImageView!.alpha = 0.0 | |
fetchCell.backgroundImage = image | |
UIView.animateWithDuration(showImageAnimationSpeed, animations: { () -> Void in | |
fetchCell.backgroundImageView!.alpha = 1.0 | |
}) | |
} | |
if #available(iOS 9.0, *) { | |
if NSProcessInfo.processInfo().lowPowerModeEnabled { | |
fetchCell.backgroundImage = image | |
} | |
else { | |
fadeInImage() | |
} | |
} | |
else { | |
fadeInImage() | |
} | |
} | |
else { | |
// THIS IS THE ISSUE. | |
// indexPathForCell will return nill, cellForRowAtIndexPath is nil, and if I set the image | |
// on the cell directly (look at the else statement directly below) | |
// it will make the wrong cells load the wrong images when scrolling fast and all | |
print("Cant find cell at index path: \(indexPath)") | |
print(self.tableView.numberOfRowsInSection(0)) | |
print(NSThread.currentThread()) | |
} | |
} | |
else { | |
// Set image | |
cell.backgroundImage = image | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment