How to check viewcontroller is added in stack or not

后端 未结 10 775
北恋
北恋 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:09

    Swift 5(Working tested). Better way to check whether the view controller is stacked in navigation or not is by simply asking for the view controller's accessibility.See example below.I use this snippet to go back to previous view controller.

        if self.navigationController?.accessibilityActivate() != nil {
            self.navigationController?.popViewController(animated: true)
        } else {
            self.dismiss(animated: true, completion: nil)
        }
    

提交回复
热议问题