Ios 内存和CPU问题单击后退按钮-Swift
我的应用程序有一个内存\ CPU的问题:当我在一个特定页面上按下我的后退按钮时,内存和CPU会不断增长,因此应用程序崩溃 我使用的滚动视图大约有40个按钮,具有特殊属性和约束。每个按钮都有一个功能。在我的页面上,还有许多视图构成了一个网格。 我只有在按下这个特定页面上的后退按钮时才会出现这个问题 可能页面太大了?我还使用此功能关闭页面,但不起作用:Ios 内存和CPU问题单击后退按钮-Swift,ios,swift,memory-management,out-of-memory,cpu,Ios,Swift,Memory Management,Out Of Memory,Cpu,我的应用程序有一个内存\ CPU的问题:当我在一个特定页面上按下我的后退按钮时,内存和CPU会不断增长,因此应用程序崩溃 我使用的滚动视图大约有40个按钮,具有特殊属性和约束。每个按钮都有一个功能。在我的页面上,还有许多视图构成了一个网格。 我只有在按下这个特定页面上的后退按钮时才会出现这个问题 可能页面太大了?我还使用此功能关闭页面,但不起作用: func back(sender: UIBarButtonItem) { // Go back to the previous V
func back(sender: UIBarButtonItem) {
// Go back to the previous ViewController
navigationController?.popViewController(animated: true)
}
这是我按下按钮时更改UILabel背景颜色的功能:
func changeColor(sender: ElectroButton){
let args = arrayFunc
weak var label1, label2, label3, label4: ElectroLabel!
for arg in args {
if arg.objectType == "LBL" && arg.variableName == sender.variableName{
print(arg.variableName, sender.variableName)
let label = arg as! ElectroLabel
label.redColor = sender.redColor
label.blueColor = sender.blueColor
label.greenColor = sender.greenColor
label.backgroundColor = UIColor(colorLiteralRed: label.redColor, green: label.greenColor, blue: label.blueColor, alpha: 1)
label.actualValue = sender.actualValue
}
if arg.objectType == "LBL"{
switch arg.variableName! {
case "LBL1":
label1 = arg as! ElectroLabel
case "LBL2":
label2 = arg as! ElectroLabel
case "LBL3":
label3 = arg as! ElectroLabel
case "LBL4":
label4 = arg as! ElectroLabel
default:
break
}
}
}
for arg in args {
if arg.objectType == "LBL" && arg.variableName == "RRISULTANTE"{
let label = arg as! ElectroLabel
let firstCh = label.variableSymbol.characters.first
for el in sender.dictOfMeasure{
if "\(firstCh!)" == el.value{
let index = label.variableSymbol.index((label.variableSymbol.startIndex), offsetBy: 1)
label.variableSymbol = label.variableSymbol.substring(from: index)
break
}
}
label.actualKey = "4"
let result = ((label1.actualValue! + label2.actualValue!) as NSString).floatValue * (label3.actualValue! as NSString).floatValue
label.actualValue = String(result)
self.changeSymbOp3(sender: label)
label.text = label.actualValue + " " + label.variableSymbol + " " + label4.actualValue + " %"
}
}
}
这是我在页面中定位对象的功能:
func detectElementPosition(arrayPos: Array<String>, object: AnyObject){
var a = 0
var b = 0
while a < 121 {
let row: UIView? = {
let row = UIView()
row.translatesAutoresizingMaskIntoConstraints = false
scrollView.addSubview(row)
return row
}()
row.widthAnchor.constraint(equalTo: section_width).isActive = true
row.heightAnchor.constraint(equalToConstant: 0).isActive = true
row.topAnchor.constraint(equalTo: scrollView.topAnchor, constant: box_height*CGFloat(a)).isActive = true
if a == Int(arrayPos[2]) {
object.topAnchor.constraint(equalTo: row.bottomAnchor).isActive = true
}
if a == Int(arrayPos[3]) {
object.bottomAnchor.constraint(equalTo: row.topAnchor).isActive = true
}
a+=1
}
while b < 51 {
let line: UIView = {
let section = UIView()
section.translatesAutoresizingMaskIntoConstraints = false
//section.backgroundColor = UIColor.black
return section
}()
scrollView.addSubview(line)
line.heightAnchor.constraint(equalTo: section_height).isActive = true
line.widthAnchor.constraint(equalToConstant: 0).isActive = true
line.leftAnchor.constraint(equalTo: scrollView.leftAnchor, constant: box_width*CGFloat(b)).isActive = true
if b == Int(arrayPos[4]) {
object.leftAnchor.constraint(equalTo: line.rightAnchor).isActive = true
}
if b == Int(arrayPos[5]) {
object.rightAnchor.constraint(equalTo: line.leftAnchor).isActive = true
}
b+=1
}
}
有什么想法吗?你说应用程序崩溃了?你有堆栈跟踪吗?如果你有,你应该把它贴出来。您提供的信息量不足以确定实际问题。此外,与其描述问题,不如展示问题,因为您的描述可能不如原始信息本身更能说明问题
Message from debugger: Terminated due to memory issue