ios - Memory and CPU problems clicking back button - Swift -
my app has memory\cpu's problem: when press button in specific page memory , cpu grow , grow , app crashes.
i use scrollview 40 buttons special properties , constraints. each button has function. there many views form grid on page. have problem when press button in specific page.
probably page big? have used function dismiss page without effect:
func back(sender: uibarbuttonitem) { // go previous viewcontroller navigationcontroller?.popviewcontroller(animated: true) }
this function change uilabel background color when press button:
func changecolor(sender: electrobutton){ let args = arrayfunc weak var label1, label2, label3, label4: electrolabel! 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 } } } arg in args { if arg.objecttype == "lbl" && arg.variablename == "rrisultante"{ let label = arg as! electrolabel let firstch = label.variablesymbol.characters.first 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!) nsstring).floatvalue * (label3.actualvalue! nsstring).floatvalue label.actualvalue = string(result) self.changesymbop3(sender: label) label.text = label.actualvalue + " " + label.variablesymbol + " " + label4.actualvalue + " %" } } }
this func position objects in page:
func detectelementposition(arraypos: array<string>, object: anyobject){ var = 0 var b = 0 while < 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 == int(arraypos[2]) { object.topanchor.constraint(equalto: row.bottomanchor).isactive = true } if == 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 } }
this output:
message debugger: terminated due memory issue
any ideas?
Comments
Post a Comment