Search code examples
iphoneiosobjective-cxcodeios6

Reusing a View Controller with both push and modal segues


I have a View Controller that I want to re-use. I want to use it with a push segue when editing some data and I want to present it modally when adding new data. I do need a bar in the top with a Cancel and a Save button when presenting it modally. I only need the Save button in the other case.

Obviously, the bar (and buttons) are only shown when I use a push segue.

Is there a way to re-use this View Controller and be able to use both a push and a modal segue?


Solution

  • You can do it as Mital says but if you dont want to add a Bool try this:

    if(self.presentingViewController != nil)
    {
        //VC is presented modally
    }
    
    else
    {
       //VC is pushed
    }
    

    It works as a charm for me.