Display cancel button when the VC is presented, don't display cancel button when the same VC is pushed

202 views Asked by At

I have a ViewController that need to display in two places.

In first place, the VC need to present and dismiss using a cancel button in its navigation bar.

In second place, the VC need to push to a navigation stack(its presented modally too) and cannot close (user have to use the back button in navigation stack).

I can display the VC in both places correctly but cannot use the close button properly. When I add the cancel bar button item to the VC, it appears in both scenarios. How can I show the cancel button when the VC is presented and hide it when the VC is pushed?

1

There are 1 answers

3
ShashiKant_B On

Using isBeingPresented you can manage your cancel button,

        if self.isBeingPresented {
           debugPrint("Controller is Presented")
        } else {
            debugPrint("Controller is Pushed")
         }