Saturday, January 13, 2024
HomeiOS Developmentios - Name a perform solely as soon as in UIViewController when...

ios – Name a perform solely as soon as in UIViewController when a UIButton is clicked


For those who put returnToView into your viewDidLoad it won’t be executed as a result of on the time viewDidLoad will get known as, the view controller itself has not absolutely setup but and it is not seen on the window hierarchy. So you can’t use current. You could assume to place it in viewWillAppear or viewDidAppear. Nonetheless, it has a downside: everytime you again from one other current or again from navigationController.pushViewController, it’ll get known as once more.

So, I feel it will obtain your purpose. It really works on a single occasion of ViewController.

class ViewController: UIViewController {
    non-public var isExecuteSaveFunc = false
    
    @objc func returnToView(_ sender: UIButton) {
        let vsdd = SavedCanvasViewController()

        if !isExecuteSaveFunc {
            savedFunc()
            isExecuteSaveFunc = true
        }
     
        vsdd.modalPresentationStyle = .fullScreen
        vsdd.modalTransitionStyle = .coverVertical
        current(vsdd, animated: true)
    } 
}

In case you need savedFunc to execute as soon as in the course of the lifetime of the app, I feel UserDefaults will match.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments