问题
I am trying to run my app which uses this GitHub project: https://github.com/PaoloCuscela/Cards/wiki/Overview
But when I run my app on my iPhone 6, it crashes and gives me the error in the title.
I've written 28 of these in my viewDidLoad
function and the app runs fine on the simulator.
let tennisCard = CardHighlight(frame: CGRect(x: 67, y: 3362, width: 250, height: 300))
tennisCard.title = "Exercise 11"
tennisCard.itemTitle = "Tennis"
tennisCard.backgroundColor = UIColor(red: 0/255, green: 255/255, blue: 79/255, alpha: 1)
tennisCard.buttonText = "See"
tennisCard.itemSubtitle = ""
tennisCard.tintColor = UIColor.black
tennisCard.textColor = UIColor.black
tennisCard.icon = UIImage(named: "Tennis")
let tennisVC = storyboard?.instantiateViewController(withIdentifier: "TennisCardContent")
tennisCard.shouldPresent(tennisVC, from: self)
scrollView.addSubview(tennisCard)
回答1:
It seems like your app uses to much resources.
First of all, check if your assets have big file sizes, and if that is the case resize them to a lower resolution.
Also loading all of these (mostly hidden below the visible area) views into the scroll view at once is very memory inefficient. Try using a table view or collection view that only loads these views when visible. This could also help you get rid of code duplication
来源:https://stackoverflow.com/questions/57606436/how-should-i-solve-this-error-thread-1-exc-resource-resource-type-memory-limi