Post

Replies

Boosts

Views

Activity

Reply to Problem with UIBarButton menu
var editmenuItems : [UIAction] { return [ UIAction(title: "Edit Value", image: UIImage(systemName: "square.and.pencil"), handler: { (_) in // self.edit() self.test() }), UIAction(title: "Fill Values", image: UIImage(systemName: "ellipsis.rectangle"), handler: { (_) in // self.fill() self.test() }) ] } and func test() { print("Test") } self is required by the compiler. Ok. I tried your suggestion. Still the CPU and wrong calculation problems continue.
Topic: UI Frameworks SubTopic: UIKit Tags:
Mar ’23
Reply to Problem with UIBarButton menu
Putting statements instead of function call does not cause CPU or wrong calculation problems. But it is not practical since some of my functions are long. var editmenuItems : [UIAction] { return [ UIAction(title: "Edit Value", image: UIImage(systemName: "square.and.pencil"), handler: { (_) in // self.test() // function call causes problems print("test" // no problem }), UIAction(title: "Fill Values", image: UIImage(systemName: "ellipsis.rectangle"), handler: { (_) in // self.test() // function causes problems print("test" // not problem }) ] } where func test() { print("test") }
Topic: UI Frameworks SubTopic: UIKit Tags:
Mar ’23
Reply to Problem with UIBarButton menu
Claude31, the class is long. However the root controller has similar code and the menus do not cause any problem on the root view controller. There are also other view controllers that are pushed from root view controller and bar button menu(s) causes the same CPU and wrong calculation problems there too. It seems related with the push (segue) from the root view controller to other view controllers. With each back to root and push to other view controller CPU load and wrong calculation amount increase. I both tried putting the bar button through storyboard and programmatically, but it did not matter in either case.
Topic: UI Frameworks SubTopic: UIKit Tags:
Mar ’23
Reply to Problem with UIBarButton menu
Claude31, I included the [self] and it did not solve the problem. In fact if the handler code does not include any class variables then the code works without CPU problems. For example, if vGlobal is a global variable and vLocal is a local variable import Foundation import UIKit var vGlobal = 0 class ViewController: UIViewController { var vLocal = 0 . . override func viewDidLoad { super.viewDidLoad() . . UIAction(title: "Edit Value", image: UIImage(systemName: "square.and.pencil"), handler: { (_) in print(self.vLocal) // problem print(vGlobal) // no problem }) . . } . . }
Topic: UI Frameworks SubTopic: UIKit Tags:
Mar ’23
Reply to Problem with UIBarButton menu
Writing the code like the below seems to resolve the CPU and wrong calculation issues at first impression. I need to do extensive tests to see if the calculations are really correct. Thank you Claude31 for your help about the [self] clause. var editmenuItems : [UIAction] { return [ UIAction(title: "Edit Value", image: UIImage(systemName: "square.and.pencil"), handler: { [weak self] (_) in self?.edit() }), UIAction(title: "Fill Values", image: UIImage(systemName: "ellipsis.rectangle"), handler: { [weak self] (_) in self?.fill() }) ] } var editMenu: UIMenu { return UIMenu(children: editmenuItems) } editButton.menu = editMenu
Topic: UI Frameworks SubTopic: UIKit Tags:
Mar ’23