0

I'd like to add a countdown to my app that reboots the app in two minutes. I dont want to restart the app physically. I only want to open the ViewController. The problem is that this function should be called from every page/ViewController.

So I created a Util/Helper class/Singleton which should handle this. But I cannot call the pushViewController method because it is no ViewController class. So I have no navigationController and I think it is not possible to pass this navigationController. How could I handle it?

Passing the navigationController to the Manager called an "unrecognized selector sent to instance" error.

@objc func decrementCounter(vc: UINavigationController) {
        if(counter == 0) {
            let viewController = ViewController()
            vc.pushViewController(viewController, animated: true)
        } else {
            counter -= 1
        }
        print("Counter: \(counter)")
    }
3
  • where is your timer code? Commented Nov 25, 2019 at 4:31
  • in my Helper/Singleton class. Not inside my viewcontroller because I want to reduce the redundant code. Commented Nov 25, 2019 at 4:39
  • @TorbenG make a function where you assign a fresh root navigation controller to the pointing to your start screen view controller , you can create a navigation controller and assign it as rootviewcontroller!! Commented Nov 25, 2019 at 10:21

2 Answers 2

1

Use your first vc to push (the vc you initial in AppDelegate).
And your first vc must be UINavigationController.
After pushed remember to remove old vc in navigation stack.

Sign up to request clarification or add additional context in comments.

Comments

0

you can try to add "#selector()" on your handler.

1 Comment

what do you mean? That I call the counter functions inside my UIViewControllers?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.