Thursday, October 29, 2026
HomeiOS Developmentios - Swift 5 - Making an attempt to dismiss all viewcontrollers...

ios – Swift 5 – Making an attempt to dismiss all viewcontrollers with navigations and modal presents

[ad_1]

im attempting to dismiss all viewcontrollers after a number of seconds.
I discovered some options for this, however doesnt work for me.

I’ve 6 view controllers, A, B, C are navigations controllers, and D, E , F use modal displays.
I need again to the preliminary view controller -> A

That is my code
Final View Controller:

    viewModel.outcome
        .observe(on: MainScheduler.occasion)
        .withUnretained(self)
        .subscribe(onNext: { proprietor, end in
            
            let vm = ResultViewModel(state: outcome)
            let vc = ResultViewController(with: vm)
            vc.modalPresentationStyle = .fullScreen
            proprietor.current(vc, animated: true)
            DispatchQueue.essential.asyncAfter(deadline: .now() + 2) {
                self.view.window!.rootViewController?.dismiss(animated: false, completion: nil)    
            }
            
        }).disposed(by: disposeBag)

Once I strive to do that, the app crashes saying window is nill.

That is my AppDelegate:

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func utility(_ utility: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  
    let window = UIWindow(body: UIScreen.essential.bounds)
    self.window = window
    let mainViewModel = MainViewModel()
    let mainViewController = MainViewController(with: mainViewModel)
    let navigationController = UINavigationController()
    navigationController.viewControllers = [mainViewController]
    
    window.rootViewController = navigationController
    window.makeKeyAndVisible()
    
    return true
}

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments