How to check viewcontroller is added in stack or not

后端 未结 10 778
北恋
北恋 2020-12-28 08:50

I have two view controllers. I have navigated from one view to another view by press the button to using below code.

 *let secondViewController = self.storyb         


        
10条回答
  •  盖世英雄少女心
    2020-12-28 09:23

    Here's another solotion:

        guard let controllersInStack = navigationController?.viewControllers else { return }
        if let yourViewController = controllersInStack.first(where: { $0 is YourViewController }) {
            // Do what you want with yourViewController
        }
    

提交回复
热议问题