Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image doesn't display #146

Open
andreimarkoff opened this issue Jun 23, 2021 · 0 comments
Open

Image doesn't display #146

andreimarkoff opened this issue Jun 23, 2021 · 0 comments

Comments

@andreimarkoff
Copy link

Hi!I am working with tmdb API and want to display some movies on a cards depending on a query(For now I try to display only one card in order to test it first).I followed the instructions on main page of this repo, and everything is fine description is displayed and I can swipe this View, except image doesn't display.Please help me if you can.Thank you!
`
import UIKit
import Shuffle_iOS

class ResultViewController: UIViewController {
let cardStack = SwipeCardStack()

var cardImages = [UIImage](){didSet {
    DispatchQueue.main.async {
        self.cardStack.reloadData()
    }
}}



var name:String = ""
var releaseDate:String = ""
var popularity:Double = 0.0
var voteAverage:Double = 0.0
var budget:Int = 0
var revenue:Int = 0
var overview:String = ""

var url:URL!
var image:UIImage!




@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var ratingLabel: UILabel!
@IBOutlet weak var budgetLabel: UILabel!
@IBOutlet weak var overviewLabel: UILabel!

override func viewDidLoad() {

    super.viewDidLoad()
    view.addSubview(cardStack)
    cardStack.frame = view.safeAreaLayoutGuide.layoutFrame
    cardStack.dataSource = self
}
override func viewWillAppear(_ animated: Bool) {
    if url != nil{
        downloadImage(from: url)
        DispatchQueue.main.async {
            self.titleLabel.text = self.name + "(" + self.releaseDate + ")"
            self.ratingLabel.text = String(self.popularity) + "     " + String(self.voteAverage)
            self.budgetLabel.text = "Budget: " + String(self.budget) + "Revenue: " + String(self.revenue)
            self.overviewLabel.text = self.overview
        }
    }
}

}
extension ResultViewController{
func getData(from url: URL, completion: @escaping (Data?, URLResponse?, Error?) -> ()) {
URLSession.shared.dataTask(with: url, completionHandler: completion).resume()
}
func downloadImage(from url: URL) {
getData(from: url) { data, response, error in
guard let data = data, error == nil else { return }
DispatchQueue.main.async() {
let image = UIImage(data: data)
if image != nil{
self.cardImages.append(image!)
print(self.cardImages)

            }
        }
    }
}

}
extension ResultViewController:SwipeCardStackDataSource{
func cardStack(_ cardStack: SwipeCardStack, cardForIndexAt index: Int) -> SwipeCard {
return card(fromImage: cardImages[index])
}

func numberOfCards(in cardStack: SwipeCardStack) -> Int {
    cardImages.count
}
func card(fromImage image: UIImage) -> SwipeCard {
  let card = SwipeCard()
  card.swipeDirections = [.left, .right]
  card.content = UIImageView(image: image)
  
  let leftOverlay = UIView()
  leftOverlay.backgroundColor = .green
  
  let rightOverlay = UIView()
  rightOverlay.backgroundColor = .red
  
  card.setOverlays([.left: leftOverlay, .right: rightOverlay])
  
  return card
}

}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant