Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  2. print(indexPath.row)
  3. if itemStyle == .Grid {
  4.  
  5. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: self.resourceCellIdentifier, for: indexPath) as! ResourceCollectionViewCell
  6. cell.delegate = self
  7. cell.tag = indexPath.row
  8.  
  9. if self.filter == Filter.Collections || self.resourceArray?[indexPath.row].actionContent == nil {
  10. let resource: ActionContentTemplate?
  11. if self.filter == Filter.Collections {
  12. resource = self.collectionResourceArray?[indexPath.row].actionContentTemplate
  13. } else {
  14. resource = self.resourceArray?[indexPath.row].actionContentTemplate
  15. }
  16.  
  17. DispatchQueue.global(qos: .userInitiated).async {
  18.  
  19. cell.dataObject = resource
  20. }
  21. return cell
  22.  
  23. } else {.....
  24.  
  25. var dataObject: ActionContentTemplate? {
  26. didSet {
  27. var cellRow: Int = 0
  28.  
  29. if self.actionContentTemplate != nil {
  30. ....
  31.  
  32. DispatchQueue.main.async {
  33. cellRow = self.tag
  34.  
  35. .....
  36.  
  37. switch self.actionContentTemplate?.contentTypeID?.uintValue {
  38. case ContentTypeVideo.rawValue,
  39. ContentTypeVideoRecording.rawValue,
  40. ContentTypeScreenRecording.rawValue:
  41. .......
  42. case ContentTypeAttachment.rawValue:
  43.  
  44.  
  45. let fileType = (self.actionContentTemplate?.contentFileName as NSString?)?.pathExtension.lowercased()
  46. var placeholderImage: UIImage
  47.  
  48. if fileType == "pdf" {
  49. placeholderImage = UIImage(named: "pdf")!
  50. } else if fileType == "doc" {
  51. placeholderImage = UIImage(named: "doc")!
  52. } else if fileType == "docx" {
  53. placeholderImage = UIImage(named: "doc")!
  54. } else if fileType == "xls" {
  55. placeholderImage = UIImage(named: "xls")!
  56. } else if fileType == "xlsx" {
  57. placeholderImage = UIImage(named: "xls")!
  58. } else if fileType == "ppt" {
  59. placeholderImage = UIImage(named: "ppt")!
  60. } else if fileType == "pptx" {
  61. placeholderImage = UIImage(named: "ppt")!
  62. } else {
  63. placeholderImage = UIImage(named: "plain")!
  64. }
  65.  
  66. if let urlString = self.actionContentTemplate?.thumbnailURL {
  67. let imageURL = URL(string: urlString)
  68.  
  69. SDWebImageManager.shared().loadImage(with: imageURL, options: [.continueInBackground, .scaleDownLargeImages], progress: nil) { (image, data, err, cacheType, finished, url) in
  70. DispatchQueue.main.async {
  71. if cellRow == self.tag {
  72.  
  73. self.activityIndicator?.stopAnimating()
  74. self.imageView.image = image
  75. UIAnimation.fadeTransitionImageView(self.imageView)
  76. }
  77. }
  78. }
  79. }
  80.  
  81. } else {
  82. DispatchQueue.main.async {
  83.  
  84. self.activityIndicator?.stopAnimating()
  85. self.imageView.image = placeholderImage
  86. }
  87. }
  88. break
  89. .....
  90.  
  91. SDWebImageManager.shared().loadImage(with: imageURL, options: [.continueInBackground, .scaleDownLargeImages], progress: nil) { (image, data, err, cacheType, finished, url) in
  92. DispatchQueue.main.async {
  93. if cellRow == self.tag {
  94. //IF I COMMENT OUT THESE TWO LINES BELOW THE ISSUES STOP (I think it is only the self.imageView.image = image line that is causing issues)
  95. // self.activityIndicator?.stopAnimating()
  96. // self.imageView.image = image
  97. UIAnimation.fadeTransitionImageView(self.imageView)
  98. }
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement