I push (show segue) from root view controller to VC2. VC2 has the below code for setting a menu for a bar button item.
If I comment out the last line, "editButton.menu = editMenu", CPU usage is stable.
Otherwise, each time VC2 is displayed, CPU usage continues to increase and also some calculations become wrong.
Same code is also present in the root view controller and in the root view controller it works fine without commenting out the problem line.
@IBOutlet weak var editButton: UIBarButtonItem!
In viewDidLoad:
var editmenuItems : [UIAction] {
return [
UIAction(title: "Edit Value", image: UIImage(systemName: "square.and.pencil"), handler: {
(_) in
self.edit()
}),
UIAction(title: "Fill Values", image: UIImage(systemName: "ellipsis.rectangle"), handler: {
(_) in
self.fill()
})
]
}
var editMenu: UIMenu {
return UIMenu(children: editmenuItems)
}
editButton.menu = editMenu // this line causes CPU increase in VC2.
I am using Xcode 14.2, iPhone only app, minimum iOS 15.0