gpt4 book ai didi

xcode - 由于内存错误而终止的应用程序

转载 作者:行者123 更新时间:2023-11-28 07:02:13 25 4
gpt4 key购买 nike

一切都很好,但是当我将我的应用程序连接到我的设备时。

在我点击按钮看到一些图片后,出现了这个错误。

我使用了很多图片,所以当人们点击一个按钮时,它会随机显示不同的图片。

我不知道为什么会显示这个错误,我看了很多类似的问题,但没有找到任何解决方案。

override func viewDidLoad() {
super.viewDidLoad()
ButtonStyle()


self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.translucent = true



let quote = randomQuote()
QuotesLabel.text = quote
QuotesLabel.textColor = UIColor.whiteColor()
QuotesLabel.font = UIFont.systemFontOfSize(30)
QuotesLabel.text = QuotesLabel.text?.uppercaseString
QuotesLabel.numberOfLines = 0

// random background image
var random = arc4random_uniform(20)
switch(random){

case 0: ChangingBackground.image = UIImage(named: "backgroundiphone.jpg")
break
case 1: ChangingBackground.image = UIImage(named: "backgroundiphone2.jpg")
break
case 2: ChangingBackground.image = UIImage(named: "backgroundiphone3.jpg")
break
case 3: ChangingBackground.image = UIImage(named: "backgroundiphone4.jpg")
break
case 4: ChangingBackground.image = UIImage(named: "backgroundiphone5.jpg")
break
case 5: ChangingBackground.image = UIImage(named: "backgroundiphone6.jpg")
break
case 6: ChangingBackground.image = UIImage(named: "backgroundiphone7.jpg")
break
case 7: ChangingBackground.image = UIImage(named: "backgroundiphone8.jpg")
break
case 8: ChangingBackground.image = UIImage(named: "backgroundiphone9.jpg")
break
case 9: ChangingBackground.image = UIImage(named: "backgroundiphone10.jpg")
break
case 10: ChangingBackground.image = UIImage(named: "backgroundiphone11.jpg")
break
case 11: ChangingBackground.image = UIImage(named: "backgroundiphone12.jpg")
break
case 12: ChangingBackground.image = UIImage(named: "backgroundiphone13.jpg")
break
case 13: ChangingBackground.image = UIImage(named: "backgroundiphone14.jpg")
break
case 14: ChangingBackground.image = UIImage(named: "backgroundiphone15.jpg")
break
case 15: ChangingBackground.image = UIImage(named: "backgroundiphone16.jpg")
break
case 16: ChangingBackground.image = UIImage(named: "backgroundiphone17.jpg")
break
case 17: ChangingBackground.image = UIImage(named: "backgroundiphone18.jpg")
break
case 18: ChangingBackground.image = UIImage(named: "backgroundiphone19.jpg")
break
case 19: ChangingBackground.image = UIImage(named: "backgroundiphone20.jpg")
break

default:
break;

}

}


@IBAction func MotivateButtonTapped(sender: UIButton) {

let quote = randomQuote()
QuotesLabel.text = quote
QuotesLabel.textColor = UIColor.whiteColor()
QuotesLabel.font = UIFont.systemFontOfSize(30)
QuotesLabel.text = QuotesLabel.text?.uppercaseString
QuotesLabel.numberOfLines = 0

// random background image
var random = arc4random_uniform(20)
switch(random){

case 0: ChangingBackground.image = UIImage(named: "backgroundiphone.jpg")
break
case 1: ChangingBackground.image = UIImage(named: "backgroundiphone2.jpg")
break
case 2: ChangingBackground.image = UIImage(named: "backgroundiphone3.jpg")
break
case 3: ChangingBackground.image = UIImage(named: "backgroundiphone4.jpg")
break
case 4: ChangingBackground.image = UIImage(named: "backgroundiphone5.jpg")
break
case 5: ChangingBackground.image = UIImage(named: "backgroundiphone6.jpg")
break
case 6: ChangingBackground.image = UIImage(named: "backgroundiphone7.jpg")
break
case 7: ChangingBackground.image = UIImage(named: "backgroundiphone8.jpg")
break
case 8: ChangingBackground.image = UIImage(named: "backgroundiphone9.jpg")
break
case 9: ChangingBackground.image = UIImage(named: "backgroundiphone10.jpg")
break
case 10: ChangingBackground.image = UIImage(named: "backgroundiphone11.jpg")
break
case 11: ChangingBackground.image = UIImage(named: "backgroundiphone12.jpg")
break
case 12: ChangingBackground.image = UIImage(named: "backgroundiphone13.jpg")
break
case 13: ChangingBackground.image = UIImage(named: "backgroundiphone14.jpg")
break
case 14: ChangingBackground.image = UIImage(named: "backgroundiphone15.jpg")
break
case 15: ChangingBackground.image = UIImage(named: "backgroundiphone16.jpg")
break
case 16: ChangingBackground.image = UIImage(named: "backgroundiphone17.jpg")
break
case 17: ChangingBackground.image = UIImage(named: "backgroundiphone18.jpg")
break
case 18: ChangingBackground.image = UIImage(named: "backgroundiphone19.jpg")
break
case 19: ChangingBackground.image = UIImage(named: "backgroundiphone20.jpg")
break

default:
break;

}




}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


// here is the image

https://drive.google.com/file/d/0B2z_d4wEKPEFMU5lSjBqYTJtX1k/view?usp=sharing

最佳答案

由于图像是 4425 * 2950 并且给定 4 字节困惑,因此在渲染时每个图像都需要 52+ MB。有几个选项:

  1. 如果图像是应用程序的一部分,请在添加到应用程序之前减小尺寸,使用多种图形程序中的任何一种来执行此操作,我使用 Graphic Converter .

  2. 如果无法在加载缩放图像后立即缩小尺寸,请将此代码放入自动释放池 autoreleasepool { scalling code } 中,这样临时内存将被释放为尽快。

  3. 如果您需要此尺寸的图像(例如平移),并且由于尺寸远大于显示区域,请在添加到项目之前创建图 block 并使用图 block 算法,例如 Apple Maps .

关于xcode - 由于内存错误而终止的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31758678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com